Skip to content

Stop a story's note box taking focus again on each return to that story - #124

Open
selfie-bot wants to merge 1 commit into
mainfrom
fix/note-focus-on-revisit
Open

selfie-bot wants to merge 1 commit into
mainfrom
fix/note-focus-on-revisit

Conversation

@selfie-bot

Copy link
Copy Markdown
Collaborator

On a story nobody has rendered yet, Write a note on this (m) renders the story and then opens its note box, as docs/specs/ui.md says. After that, though, the note box took focus again every time someone came back to that story with j/k, so the next keys went into the text box instead of moving through stories. This PR makes the request apply once: OneStory drops it as soon as someone moves to another story.

Cause. StoriesRoutes renders OneStory without a key, so the component and its state stay mounted across stories. noteOn was set in StoriesScreen.tsx and never cleared, so startNote={noteOn === story} became true again on each return. That re-ran the focus effect in ImageCompare.tsx, which depends on [startNote].

Fix. noteOn is reset during render when the story changes, React's pattern for adjusting state when a prop changes. That keeps OneStory mounted, so a key doesn't refetch the batch on every j/k.

Testing. There's no regression test. ui/ has no component test harness: its vitest suites are non-DOM. Covering this would take a story with a play function driving StoriesRoutes against mocked useStories/useBatch data, which no existing story does. pnpm typecheck in ui/ passes. Found in the nightly survey by reading the code, not from a reported failure.

…to it

OneStory stays mounted while j and k move between stories, so the story
someone pressed m on stayed in noteOn, and startNote turned true again on
every return to it, focusing the note box and taking the next keys.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant