Commit e2ef681
authored
Previously, we called `onHidden` in our slightly modified version of the
vendored in `whenIdleOrHidden` API from web-vitals. This caused 2
additional event listeners to be registered with each `whenIdleOrHidden`
invocation, which also didn't get cleaned up properly.
To fix this, and prevent similar situations, this PR:
- inlines the `pagehide` event listener registration in
`whenIdleOrHidden` so that we can remove the `onHidden` call
- adds `once: true` to the listener registration so that the callback is
only invoked once
- deprecates `onHidden` because IMHO we should remove it in v11 and
replace the one remaining use of it with a direct `visibilityChange`
subscription.
Closes #18584 (added automatically)
closes
https://linear.app/getsentry/issue/JS-1339/investigate-multiple-event-listeners-in-nextjs-sdk
1 parent aaa0fea commit e2ef681
File tree
3 files changed
+32
-17
lines changed- packages/browser-utils/src/metrics
- web-vitals/lib
3 files changed
+32
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| |||
Lines changed: 24 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
34 | 46 | | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | | - | |
| 53 | + | |
42 | 54 | | |
43 | 55 | | |
44 | | - | |
| 56 | + | |
45 | 57 | | |
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 49 | | |
48 | 50 | | |
0 commit comments