Skip to content

Commit c413753

Browse files
authoredJan 11, 2023
[fix] no false positive warnings for fetch uses in firefox (#8456)
fixes #7992
1 parent 40dd7d9 commit c413753

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
 

‎.changeset/shy-readers-help.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] no false positive warnings for fetch uses in firefox

‎packages/kit/src/runtime/client/fetcher.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ if (DEV) {
2424
check_stack_trace();
2525

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.