-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
fix(context): Deduplicate wxt:content-script-started
#1364
Conversation
> This fix prevents premature context invalidation > fixes #1359
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Not by design, I'm curious what is sending the message a second time... Is the message coming from a different frame? The same frame? I don't really understand why we need to deduplicate handling the event when we shouldn't be sending the event a second time in the first place. |
When I was debugging the library, I have noticed that wxt doesn't send the event twice but rather the page I've linked would sporadically dispatch the events again. With the uglified source code it's hard to say what their justification was. Are you able to reproduce the issue? |
No, I was not. A separate issue with vite 6.0.9 prevented me from following the repro steps. Been trying to fix that. See #1359 and #1362 But ok, the website sending the event more than one makes sense, thanks for the additional info. In the case, since we can't control when the website re-sends the events or if it can change the event values, we should previously use the ID approach you mentioned instead of a timestamp. |
I've revised the PR to use UUID. Last commit b099287 can be reverted if it's not necessary to validate the origin of the messages. |
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.
Thanks, it looks good now. Last change - Can we just use Math.random
for the ID instead of installing a new package? Or if you want to use a UUID, the builtin crypto API can generate one for you on modern browsers:
https://developer.mozilla.org/en-US/docs/Web/API/Crypto
const id = crypto?.randomUUID?.() ?? Math.rand()
But I think a random number would be fine. Then we don't need to check if the crypto API is available.
Sure, I didn't want to use |
packages/wxt/src/client/content-scripts/content-script-context.ts
Outdated
Show resolved
Hide resolved
Nice, thanks. Running checks, will get this merged and deployed once they pass and I get back on |
@wxt-dev/auto-icons
@wxt-dev/module-solid
@wxt-dev/i18n
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/module-react
@wxt-dev/storage
@wxt-dev/unocss
wxt
commit: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1364 +/- ##
==========================================
- Coverage 81.34% 81.21% -0.14%
==========================================
Files 128 128
Lines 6288 6296 +8
Branches 1072 1073 +1
==========================================
- Hits 5115 5113 -2
- Misses 1158 1168 +10
Partials 15 15 ☔ View full report in Codecov by Sentry. |
wxt:content-script-started
wxt:content-script-started
This fix prevents premature context invalidation. Some pages might send the same message again, either by design or a flaw. That shouldn't interfere with the context invalidation logic.
We could go even further and add a UUID to the event in
stopOldScripts
and check that but timestamp might be good enough.fixes #1359