Skip to content

Commit

Permalink
[fix] no false positive warnings for fetch uses in firefox (#8456)
Browse files Browse the repository at this point in the history
fixes #7992
  • Loading branch information
dummdidumm committed Jan 11, 2023
1 parent 40dd7d9 commit c413753
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-readers-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] no false positive warnings for fetch uses in firefox
16 changes: 12 additions & 4 deletions packages/kit/src/runtime/client/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ if (DEV) {
check_stack_trace();

window.fetch = (input, init) => {
// Check if fetch was called via load_node. the lock method only checks if it was called at the
// same time, but not necessarily if it was called from `load`.
// We use just the filename as the method name sometimes does not appear on the CI.
const url = input instanceof Request ? input.url : input.toString();
const stack = /** @type {string} */ (new Error().stack);
const stack_array = /** @type {string} */ (new Error().stack).split('\n');
// We need to do some Firefox-specific cutoff because it (impressively) maintains the stack
// across events and for example traces a `fetch` call triggered from a button back
// to the creation of the event listener and the element creation itself,
// where at some point client.js will show up, leading to false positives.
const firefox_cutoff = stack_array.findIndex((a) => a.includes('*listen@'));
const stack = stack_array
.slice(0, firefox_cutoff !== -1 ? firefox_cutoff : undefined)
.join('\n');

// check if fetch was called via load_node. the lock method only checks if it was called at the
// same time, but not necessarily if it was called from `load`
// we use just the filename as the method name sometimes does not appear on the CI
const heuristic = can_inspect_stack_trace
? stack.includes('src/runtime/client/client.js')
: loading;
Expand Down

0 comments on commit c413753

Please sign in to comment.