Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DustinJSilk
Copy link
Contributor

@DustinJSilk DustinJSilk commented Oct 7, 2024

What is it?

  • Bug

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:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • I have ran pnpm change and documented my changes
  • Added new tests to cover the fix / functionality

@DustinJSilk DustinJSilk requested a review from a team as a code owner October 7, 2024 09:42
Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: e7f00cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik Patch
eslint-plugin-qwik Patch
@builder.io/qwik-city Patch
create-qwik Patch

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

Copy link

pkg-pr-new bot commented Oct 7, 2024

Open in Stackblitz

npm i https://pkg.pr.new/@builder.io/qwik@6942
npm i https://pkg.pr.new/@builder.io/qwik-city@6942
npm i https://pkg.pr.new/eslint-plugin-qwik@6942
npm i https://pkg.pr.new/create-qwik@6942

commit: e7f00cb

Copy link
Contributor

github-actions bot commented Oct 7, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 53557dc

.changeset/lucky-snails-think.md Outdated Show resolved Hide resolved
.changeset/lucky-snails-think.md Outdated Show resolved Hide resolved
@@ -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]);
Copy link
Member

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]]?

Copy link
Contributor Author

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?

DustinJSilk and others added 2 commits October 13, 2024 23:25
Co-authored-by: Wout Mertens <Wout.Mertens@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[🐞] Unknown messages throw an error on PrefetchServiceWorker
3 participants