-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: validate prefetch-sw messages #6942
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: e7f00cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
@@ -46,3 +48,7 @@ export const setupServiceWorker = (swScope: ServiceWorkerGlobalScope) => { | |||
event.waitUntil(swScope.clients.claim()); | |||
}); | |||
}; | |||
|
|||
function isQwikMessages(msg: any): msg is SWMessages { | |||
return msg[0] && Object.values(MsgType).includes(msg[0][0]); |
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.
every message that comes in you generate an array of all the values in the enum. How about renaming the enum values so they are lowercase and you can do !!MsgType[msg[0][0]]
?
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.
Ah yes you’re right. Hmm, the tricky part is that some of the enum values can’t be valid enum keys, like graph-url
. We could generate the array once outside of the function. I’m not sure what a better solution could be, what do you think?
Co-authored-by: Wout Mertens <[email protected]>
What is it?
Description
fixes: #6921
If an unknown message is sent to the SW which isn't an array, Qwik throws an error attempting to slice the array. If it is an array type, Qwik will log an error. This PR will check if messages are Qwik messages before queuing them and ignore unknown messages.
Checklist:
pnpm change
and documented my changes