-
Notifications
You must be signed in to change notification settings - Fork 227
refactor: replace cross-tab chrome.storage sync with sinking #160
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -8,16 +8,6 @@ chrome.storage.onChanged.addListener((changes) => { | |
| "*", | ||
| ); | ||
| } | ||
|
|
||
| if (changes.react_grab_toolbar_state) { | ||
| const newState = changes.react_grab_toolbar_state.newValue; | ||
| if (newState) { | ||
| window.postMessage( | ||
| { type: "__REACT_GRAB_TOOLBAR_STATE_CHANGE__", state: newState }, | ||
| "*", | ||
| ); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { | ||
|
|
@@ -38,25 +28,21 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { | |
|
|
||
| window.addEventListener("message", (event) => { | ||
| if (event.data?.type === "__REACT_GRAB_QUERY_STATE__") { | ||
| chrome.storage.local.get( | ||
| ["react_grab_enabled", "react_grab_toolbar_state"], | ||
| (result) => { | ||
| const enabled = result.react_grab_enabled ?? true; | ||
| const toolbarState = result.react_grab_toolbar_state ?? null; | ||
| chrome.storage.local.get(["react_grab_enabled"], (result) => { | ||
| const enabled = result.react_grab_enabled ?? true; | ||
|
|
||
| window.postMessage( | ||
| { | ||
| type: "__REACT_GRAB_STATE_RESPONSE__", | ||
| enabled, | ||
| toolbarState, | ||
| }, | ||
| "*", | ||
| ); | ||
| }, | ||
| ); | ||
| window.postMessage( | ||
| { | ||
| type: "__REACT_GRAB_STATE_RESPONSE__", | ||
| enabled, | ||
| }, | ||
| "*", | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| if (event.data?.type === "__REACT_GRAB_TOOLBAR_STATE_SAVE__") { | ||
| chrome.storage.local.set({ react_grab_toolbar_state: event.data.state }); | ||
| if (event.data?.type === "__REACT_GRAB_GET_WORKER_URL__") { | ||
| const workerUrl = chrome.runtime.getURL("src/worker.ts"); | ||
|
Contributor
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. Incorrect path: Similar to manifest.json issue—this references the source TypeScript file instead of the compiled JavaScript. |
||
| window.postMessage({ type: "__REACT_GRAB_WORKER_URL__", workerUrl }, "*"); | ||
| } | ||
| }); | ||
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.
Critical inconsistency: Initial load uses
initialOptions.persistToolbarStatebut runtime checks usepluginRegistry.store.options.persistToolbarState. IfsetOptions({ persistToolbarState: false })is called (which the extension does at line 93 of react-grab.ts),shouldPersistToolbarState()will correctly return false, but this initial load already happened with the wrong value. The extension explicitly passespersistToolbarState: falsein initial options, so this specific code path works, but the inconsistent pattern is fragile—if initialization order changes or if someone callssetOptionsbefore the toolbar mounts, this breaks.