Present: a follower knows the slide by its id, not its number
After a reorder the slide at a number can be another one: a follower on B, second, took the talk's move to A, now second too, for a step of B and fetched nothing. The surface and the remote now say the slide's id (data-slide-id) on a session with a position, and present.js compares it with the event's slideId before treating an event as a step in place; a page without a stage reloads for it. Review finding, Important 2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+68
−7
internal/slides/credits/assets.json+1 −1internal/slides/presentation.go+13 −1internal/slides/static/present.js+16 −3internal/slides/templates/present.html+1 −1internal/slides/templates/remote.html+1 −1internal/slidestest/present_steps_browser_test.go+36 −0
diff --git a/internal/slides/credits/assets.json b/internal/slides/credits/assets.json| index 1d902a4..5d2f179 100644 |
| --- a/internal/slides/credits/assets.json |
| +++ b/internal/slides/credits/assets.json |
| @@ -68,7 +68,7 @@ |
| "internal/slides/static/fonts/LiberationSerif-Regular.woff2": "922f544d0eabdf45ecd389b3bb35367e670b736e40851d01e53c150352c012f2", |
| "internal/slides/static/fontsgate.971e476eab8b8588.js": "971e476eab8b8588be520ac38eb823ab19beb2567db734555a7edc40d58567b2", |
| "internal/slides/static/fontshold.876f3d8d396da42f.js": "876f3d8d396da42f81954539f30b7200edfcde719d2920504707822f176a36ab", |
| - "internal/slides/static/present.js": "41adf1e16b6352a592bf2c2c5a728af6e19a5c36fa890d67195ec0eeee2f2d6b", |
| + "internal/slides/static/present.js": "c685310f5725a79b7637bc3ae524684e3ffd4d99c4995a084b4164af8238460d", |
| "internal/slides/static/presenter.8518b3e9f7b42616.js": "8518b3e9f7b42616036680539a3d29ed4d9c2a30a497ec7f9f91247adb235e7f", |
| "internal/slides/static/rastrillo.js": "13a8ca6fa9ac25833f6485ab50a521dff7bd811372025dc5141b96522b60098b", |
| "internal/slides/static/select.js": "e231bad4b964464addfacd52d2260d4bdc0a02938fc033a25fdd9cbeb3671be1", |
diff --git a/internal/slides/presentation.go b/internal/slides/presentation.go| index 9931e96..39b29fe 100644 |
| --- a/internal/slides/presentation.go |
| +++ b/internal/slides/presentation.go |
| @@ -489,6 +489,11 @@ type surfacePage struct { |
| Token string |
| Drives bool |
| + // SlideID is the drawn slide's id on a session with a position |
| + // (data-slide-id): a slide is known by it, since the number of a |
| + // slide can be another slide's after a reorder (static/present.js). |
| + SlideID string |
| + |
| HasSlide bool |
| Slide template.HTML |
| // Now is the 1-based slide number events carry (eventFor), and |
| @@ -619,11 +624,12 @@ type remotePage struct { |
| NextLabel string |
| Next template.HTML |
| HasNext bool |
| - // Stepped, Step, StepCount and Mode: see presented. |
| + // Stepped, Step, StepCount, Mode and SlideID: see presented. |
| Stepped bool |
| Step int |
| StepCount string |
| Mode string |
| + SlideID string |
| NotesLabel string |
| Notes template.HTML |
| @@ -802,6 +808,7 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr |
| if reveal != nil { |
| mode := positionOf(p).Mode |
| page.Stepped, page.Step, page.Mode = true, *reveal, string(mode) |
| + page.SlideID = view.Slides[index].ID |
| page.Place, page.Places = talkPlace(view, mode, index) |
| } |
| page.Counter = rastrillo.Tf(r, "slides.present.progress", "n", page.Place, "total", page.Places) |
| @@ -1152,6 +1159,9 @@ type presented struct { |
| Step int |
| StepCount string |
| Mode string |
| + // SlideID is the slide's id, on a session with a position |
| + // (data-slide-id): present.js knows a slide by it. |
| + SlideID string |
| } |
| // presentedFor builds them. A slide that will not draw leaves its half |
| @@ -1171,6 +1181,7 @@ func presentedFor(r *http.Request, view *deck.Deck, p Presentation) presented { |
| var presses int |
| index, out.Step, presses = sessionPlace(view, p) |
| out.Stepped = true |
| + out.SlideID = view.Slides[index].ID |
| mode := positionOf(p).Mode |
| out.Mode = string(mode) |
| n, total = talkPlace(view, mode, index) |
| @@ -1286,6 +1297,7 @@ func (a *app) remote(w http.ResponseWriter, r *http.Request) { |
| page.Now, page.Counter, page.Current = shown.Now, shown.Counter, shown.Current |
| page.Next, page.HasNext, page.Notes = shown.Next, shown.HasNext, shown.Notes |
| page.Stepped, page.Step, page.StepCount = shown.Stepped, shown.Step, shown.StepCount |
| + page.SlideID = shown.SlideID |
| page.Mode = shown.Mode |
| render(w, "remote", page) |
| } |
diff --git a/internal/slides/static/present.js b/internal/slides/static/present.js| index 2ffb5c6..7930cbb 100644 |
| --- a/internal/slides/static/present.js |
| +++ b/internal/slides/static/present.js |
| @@ -116,6 +116,10 @@ |
| var displayed = Number(root.getAttribute('data-slide')) || 0; |
| var requested = displayed; |
| var newest = 0; |
| + // A session with a position also says the slide's id |
| + // (data-slide-id), and the slide is known by that: after a reorder |
| + // the number on the stage can be another slide's. |
| + var displayedID = root.getAttribute('data-slide-id'); |
| // Steps, on a session with a position. Its surface says which step |
| // the slide is drawn at (data-step), and each box or list item that |
| @@ -303,6 +307,9 @@ |
| } |
| var slide = Number(nextRoot.getAttribute('data-slide')) || displayed; |
| displayed = requested = slide; |
| + displayedID = nextRoot.getAttribute('data-slide-id'); |
| + if (displayedID === null) root.removeAttribute('data-slide-id'); |
| + else root.setAttribute('data-slide-id', displayedID); |
| requestedStep = shownStep(); |
| root.setAttribute('data-slide', String(slide)); |
| if (!keepBlackout) { |
| @@ -376,6 +383,7 @@ |
| // says its mode (data-mode) for a change of mode: its counter and the |
| // slide it shows coming next count through the talk being given. |
| var renderedBlackout = root.getAttribute('data-blackout') === 'true'; |
| + var renderedID = root.getAttribute('data-slide-id'); |
| var renderedStep = root.getAttribute('data-step'); |
| var renderedMode = root.getAttribute('data-mode'); |
| var reloadKey = 'slides-present-reload:' + window.location.pathname; |
| @@ -391,10 +399,12 @@ |
| var blackout = !!state.blackout; |
| if (renderedStep === null) step = null; |
| if (renderedMode === null) mode = null; |
| + var id = state.slideId && renderedID !== null ? String(state.slideId) : null; |
| if (slide === displayed && blackout === renderedBlackout && |
| + (id === null || id === renderedID) && |
| (step === null || String(step) === renderedStep) && |
| (mode === null || mode === renderedMode)) return; |
| - var want = String(slide) + (step === null ? '' : '.' + step) + |
| + var want = String(slide) + (id === null ? '' : '#' + id) + (step === null ? '' : '.' + step) + |
| (mode === null ? '' : '@' + mode) + (blackout ? ':blackout' : ''); |
| if (want === reloadedFor) return; |
| try { |
| @@ -447,7 +457,10 @@ |
| root.setAttribute('data-blackout', state.blackout ? 'true' : 'false'); |
| if (note) note.hidden = !state.blackout; |
| var slide = Number(state.slide); |
| - if (step !== null && requestedStep !== null && slide === displayed) { |
| + // The same number may be another slide since a reorder: the id |
| + // says, where both sides have one. |
| + var other = !!state.slideId && displayedID !== null && state.slideId !== displayedID; |
| + if (step !== null && requestedStep !== null && slide === displayed && !other) { |
| if (step !== requestedStep) reveal(step); |
| // Another mode on the same slide: the stage stays as it is, and |
| // the counter and the bar, which count through the talk being |
| @@ -456,7 +469,7 @@ |
| if (mode !== null && drawnMode !== null && mode !== drawnMode) show(slide, step, true); |
| return; |
| } |
| - show(slide, step); |
| + show(slide, step, other); |
| } |
| // The stream is the page's only while the page is: leaving it (another |
diff --git a/internal/slides/templates/present.html b/internal/slides/templates/present.html| index 6c58801..8822fa1 100644 |
| --- a/internal/slides/templates/present.html |
| +++ b/internal/slides/templates/present.html |
| @@ -141,7 +141,7 @@ |
| {{- if .StreamHref}} data-stream="{{.StreamHref}}"{{end}} |
| {{- if .FragmentHref}} data-fragment="{{.FragmentHref}}"{{end}} |
| data-slide="{{.Now}}" |
| - {{- if .Stepped}} data-step="{{.Step}}" data-mode="{{.Mode}}"{{end}} |
| + {{- if .Stepped}} data-step="{{.Step}}" data-mode="{{.Mode}}" data-slide-id="{{.SlideID}}"{{end}} |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}" |
| {{- with .Announce}} data-announce="{{.}}"{{end}} |
| {{- if .Token}} data-remote-token="{{.Token}}"{{end}} |
diff --git a/internal/slides/templates/remote.html b/internal/slides/templates/remote.html| index 5352017..fcad1ea 100644 |
| --- a/internal/slides/templates/remote.html |
| +++ b/internal/slides/templates/remote.html |
| @@ -61,7 +61,7 @@ |
| <div slides-remote data-session="{{.Session}}" data-remote-token="{{.Controls.Token}}" |
| data-slide="{{.Now}}" |
| - {{- if .Stepped}} data-step="{{.Step}}" data-mode="{{.Mode}}"{{end}} |
| + {{- if .Stepped}} data-step="{{.Step}}" data-mode="{{.Mode}}" data-slide-id="{{.SlideID}}"{{end}} |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}"> |
| <div slides-remote-preview> |
| <div> |
diff --git a/internal/slidestest/present_steps_browser_test.go b/internal/slidestest/present_steps_browser_test.go| index f43b507..88c59cb 100644 |
| --- a/internal/slidestest/present_steps_browser_test.go |
| +++ b/internal/slidestest/present_steps_browser_test.go |
| @@ -283,3 +283,39 @@ func TestReducedMotionAppears(t *testing.T) { |
| t.Errorf("with reduced motion, press 2 arrived as %+v, want it shown at once with no animation", got) |
| } |
| } |
| + |
| +// TestFollowFindsTheSlideByItsID: a follower showing B, second in the |
| +// talk, when the deck is reordered B, A and the talk moves on to A, |
| +// which is second too: the slide's number is the same, the slide is |
| +// not, and the follower fetches A rather than taking it for a step of B. |
| +func TestFollowFindsTheSlideByItsID(t *testing.T) { |
| + st := newStepsTalk(t) |
| + agent := mintAgent(t, st.app, st.cookies, "reorder") |
| + sqid := strings.TrimPrefix(st.deck, "/d/") |
| + view := apiJSON(t, st.app, http.MethodGet, "/api/v1/decks/"+sqid, agent, "", http.StatusOK) |
| + ops := []string{} |
| + for _, s := range view["slides"].([]any) { |
| + ops = append(ops, `{"op":"remove_slide","id":`+quote(s.(map[string]any)["id"].(string))+`}`) |
| + } |
| + for _, s := range []struct{ id, title string }{{"slidea", "Alpha"}, {"slideb", "Bravo"}, {"slidec", "Charlie"}} { |
| + ops = append(ops, |
| + `{"op":"add_slide","id":"`+s.id+`","layout":"flow","template":"title-body"}`, |
| + `{"op":"add_block","slide":"`+s.id+`","id":"`+s.id+`h","type":"heading","region":"heading","props":{"level":1},"markdown":"`+s.title+`"}`) |
| + } |
| + apiJSON(t, st.app, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", agent, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK) |
| + press(t, st.app, st.session, st.token, url.Values{"op": {"goto"}, "slide": {"2"}, "press": {newPressID(t)}}, nil) |
| + |
| + share := mintShareLink(t, st.app, st.deck, st.cookies) |
| + heading := `document.querySelector('[slides-stage] [slides-slide]')?.innerText.trim()` |
| + st.rig.Run( |
| + chromedp.Navigate(st.rig.Origin+"/s/"+share+"?follow=1"), |
| + waitFor(heading+` === 'Bravo'`), |
| + ) |
| + |
| + apiJSON(t, st.app, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", agent, `{"ops":[{"op":"move_slide","id":"slideb","after":null}]}`, http.StatusOK) |
| + at := press(t, st.app, st.session, st.token, op(t, "next"), nil) |
| + if at.Slide != "slidea" { |
| + t.Fatalf("next from Bravo, first after the reorder, reached %q, want slidea", at.Slide) |
| + } |
| + st.rig.Run(waitFor(heading + ` === 'Alpha'`)) |
| +} |