Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/experiment-tag/src/subscriptions/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,21 @@ export class SubscriptionManager {
history.pushState = function (...args) {
// Call the original pushState
const result = originalPushState.apply(this, args);
// Revert mutations and apply variants
handleUrlChange();
// Defer experiment re-evaluation so the calling navigation framework
// (e.g. Angular, Vue, MFE routers) can finish its own synchronous
// navigation cycle before we apply DOM mutations. Running synchronously
// inside pushState interleaves with framework rendering and can corrupt
// component bindings (e.g. Angular async pipe receiving non-Observable
// values).
setTimeout(handleUrlChange, 0);
return result;
};

// Wrapper for replaceState
history.replaceState = function (...args) {
// Call the original replaceState
const result = originalReplaceState.apply(this, args);
// Revert mutations and apply variants
handleUrlChange();
setTimeout(handleUrlChange, 0);
return result;
};
};
Expand Down
Loading