Repository navigation
Fix ?slide=N deep links resetting to the first slide - #79
Merged
Merged
Conversation
The viewer read the `slide` search param in a mount effect that also depended on `searchParams`. On the first commit, the URL-sync effect ran with step 0 and called history.replaceState without the param. Next mirrors replaceState into useSearchParams, so the mount effect re-ran with no param and reset the deck to step 0. Read the param once in a lazy useState initializer instead, and stop the mount effect from reading searchParams. Add parseSlideParam to clamp the step and fall back to 0 for a missing or malformed value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Loading a deck with
?slide=N(for example/slides/gettsim-2026?slide=5) showed slide 1 and removed theslideparam from the URL. This affected every deck.Cause
SlideshowViewerread theslideparam in a mount effect that depended onsearchParams. On the first commit, the URL-sync effect ran withcurrentStepstill 0 and calledhistory.replaceStatewithout the param. Next's app router mirrorsreplaceStateintouseSearchParams, so the mount effect ran again with no param and reset the deck to step 0.Fix
useStateinitializer. The mount effect no longer readssearchParams.parseSlideParam()tolib/slide-url.ts. It clamps the step to the deck and falls back to 0 for a missing or malformed value (the old code producedNaNfor?slide=abc).buildSlideUrl(), so the/slidesbasePath is preserved.Tests
components/core/SlideshowViewer.test.tsxmirrorsreplaceStateintouseSearchParamsthe way Next does. 4 of its 5 tests failed on the old code; all pass now.parseSlideParamunit tests inlib/slide-url.test.ts.bun run test(140 passed),bun run lint(0 errors),bun run typecheck,bun run buildall pass on the branch merged with currentmain.Manual check (dev server,
gettsim-2026, 37 steps)?slide=5opens at 6 / 37 and keeps the param (before: 1 / 37, param removed).?slide=abcopens at step 1;?slide=999opens at the last step.🤖 Generated with Claude Code