Skip to content

Commit 62ab066

Browse files
Paul Boocockpaulboocock
authored andcommitted
Fix race condition when using Form and Link Click tracking (close #962)
1 parent 407b460 commit 62ab066

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker-core",
5+
"comment": "Fix race condition when using Form and Link Click tracking (#962)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker-core",
10+
"email": "paul@snowplowanalytics.com"
11+
}

libraries/browser-tracker-core/src/state.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ export function createSharedState(): SharedState {
127127
}
128128
// Last attempt at flushing in beforeunload
129129
addEventListener(windowAlias, 'beforeunload', flushBuffers, false);
130-
addReadyListener();
130+
131+
if (document.readyState === 'loading') {
132+
addReadyListener();
133+
} else {
134+
loadHandler();
135+
}
131136

132137
return sharedState;
133138
}

0 commit comments

Comments
 (0)