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: prevent false positive warnings for fetch in Firefox and Safari #9680

Merged
merged 3 commits into from
Apr 17, 2023

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Apr 16, 2023

fixes #7992

Only Chrome-like browsers have a short stack trace, leading to a correct fetch warning. However, Safari and Firefox both have a stack trace from the beginning of the client-side initialisation, leading to false positive warnings.

The fix is to cut off the stack trace at the point where the load function is invoked/mentioned. This makes the stack traces for Firefox and Safari similar to Chrome.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot
Copy link

changeset-bot bot commented Apr 16, 2023

🦋 Changeset detected

Latest commit: 2dd3bd4

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit 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

@benmccann
Copy link
Member

do you think there's some test we could add for this to the cross-browser test suite that runs in webkit?

@eltigerchino
Copy link
Member Author

do you think there's some test we could add for this to the cross-browser test suite that runs in webkit?

You're right! I think we can definitely add one. I'll try to cook up something tonight.

@eltigerchino
Copy link
Member Author

There's already a test in test/client.test.js that I considered moving to cross-platform and adapting to include the false-positive test.

if (process.env.DEV) {
test('using window.fetch causes a warning', async ({ page, baseURL }) => {
await Promise.all([
page.goto('/load/window-fetch/incorrect'),
page.waitForEvent('console', {
predicate: (message) => {
return (
message.text() ===
`Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests`
);
},
timeout: 3_000
})
]);
expect(await page.textContent('h1')).toBe('42');
/** @type {string[]} */
const warnings = [];
page.on('console', (msg) => {
if (msg.type() === 'warning') {
warnings.push(msg.text());
}
});
await page.goto('/load/window-fetch/correct');
expect(await page.textContent('h1')).toBe('42');
expect(warnings).not.toContain(
`Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests`
);
});
}

Ultimately, decided against it but did use it as a reference for the false-positive specific test in test/cross-platform/client.test.js. Still feels a bit weird not co-locating it with the actual window.fetch warning test.

@@ -742,3 +742,24 @@ test.describe('Interactivity', () => {
expect(errored).toBe(false);
});
});

test.describe('Load', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure where to put this test, or how best to describe it. Open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like as good a place as any 👍

@Rich-Harris Rich-Harris merged commit 95e9582 into master Apr 17, 2023
@Rich-Harris Rich-Harris deleted the fix-window-fetch-warning branch April 17, 2023 19:09
This was referenced Apr 17, 2023
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.

fetch from *.svelte (e.g. in button click) triggers repeated console warning not to use window.fetch
3 participants