Repository navigation
Let scanning hooks run outside a provider #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,10 +90,17 @@ export function ScanProvider({ | |
| return <ControllerContext.Provider value={controller}>{children}</ControllerContext.Provider>; | ||
| } | ||
|
|
||
| let inert: ScanController | undefined; | ||
|
|
||
| /** | ||
| * Outside a ScanProvider the hooks use one controller that is never started, so a | ||
| * shared component can call them whether or not its screen is scanned. | ||
| */ | ||
| export function useScanController(): ScanController { | ||
| const controller = useContext(ControllerContext); | ||
| if (!controller) throw new Error("Scanning hooks must be used inside a ScanProvider."); | ||
| return controller; | ||
| if (controller) return controller; | ||
| inert ??= new ScanController(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The fallback is a working, shared Artifacts
Both providerless roots report hook errors before the PR
Unrelated Tree B is highlighted after the PR
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/react/index.tsx
Line: 102
Comment:
**Provider-less controls can start scanning**
The fallback is a working, shared `ScanController`, not an inert one. Outside a `ScanProvider`, `useScanner().start()` or `dispatch("select")` starts it, and a bound key press through `useKeyboardSwitches` does the same. Controls in unrelated provider-less React trees then share its highlights and activation callbacks. This was reproduced with two separate roots: keyboard input highlighted and activated the second root's control without clicking it. Make the fallback unable to start scanning or activate items, and cover these entry points before merging.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
| return inert; | ||
| } | ||
|
|
||
| export function useScanSnapshot(): ScanSnapshot { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module-wide fallback retains every distinct item and group ID it has registered.
ScanController.sequenceOf()stores IDs insequences, but unregistering removes only the live registrations. Because this fallback lasts for the app session, provider-less lists with changing IDs keep growing that map after their rows unmount. Rendering and cleaning up two independent roots retained 400 historical IDs with no live items, groups, or subscriptions. This is a non-blocking memory-retention concern for long-running apps; avoid storing registration history in the inert fallback.Artifacts
Evidence from the check
Evidence from the check
Evidence from the check
Command output from the check
Command output from the check
Command output from the check
Prompt To Fix With AI