-
Notifications
You must be signed in to change notification settings - Fork 1
Fixes to message routing in the extension #158
Conversation
WalkthroughWalkthroughThe changes involve restructuring the asynchronous message handling logic in a Chrome extension, focusing on encapsulating operations within async functions. The modifications enhance response timing and robustness, particularly for "UNAUTHORIZED" and "NEW_EDIT" messages. The response now includes detailed modification data for better feedback. The imports have also been updated to accommodate new data types. Overall, the updates aim for clearer and more reliable message processing. Changes
Sequence Diagram(s)sequenceDiagram
participant Sender
participant Background
participant Content
Sender->>Background: Send message (e.g., "UNAUTHORIZED")
Background->>Background: Process message asynchronously
Background-->>Sender: Send response after processing
Sender->>Content: Send message (e.g., "NEW_EDIT")
Content->>Content: Process changes asynchronously
Content-->>Sender: Send modification data in response
Poem
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- apps/mocksi-lite-next/src/pages/background/index.ts (1 hunks)
- apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (2 hunks)
Additional comments not posted (3)
apps/mocksi-lite-next/src/pages/background/index.ts (1)
77-122
: Ensure correct async handling in message listener.The restructuring of the asynchronous logic within the
chrome.runtime.onMessageExternal.addListener
is well-implemented. Wrapping the logic in an async function and returningtrue
ensures that Chrome waits for the async response. This is crucial for handling asynchronous operations correctly in Chrome extensions.apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (2)
2-2
: ImportAppliedModifications
correctly.The addition of
AppliedModifications
in the import statement suggests that modifications are being tracked. Ensure that this import is used correctly in the code.
65-126
: Async handling in message listener is well-structured.The use of an async IIFE within the message listener allows for proper handling of asynchronous operations. The inclusion of modification data in the response provides detailed feedback, which is a good enhancement.
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.
Looks solid, and while normally I would say "let's not use nested ifs", in code that uses async methods they are a necessity because it's quite easy to break the control flow by calling other functions.
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.
lgtm
These fixes make sure that messages and responses go from iframe -> service worker -> content script and all the way back.
I learned that you can't use async methods in chrome message listeners: as soon as you await something, the method returns and no response is sent. Instead the message listener needs to return true (which tells chrome the response will be async) and run the async code separately.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor