You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[馃悶] Fallback deletes dataLayer even when dataLayer.push is forwarded with preserveBehavior: true聽#789
Describe the bug
When Partytown falls back to the main thread (the service worker is unavailable or fallbackTimeout is reached), fallback() deletes the top-level global of every forward entry:
deletewin[property.split('.')[0]];
With forward: [['dataLayer.push', { preserveBehavior: true }]], pushes made before the fallback go into the real window.dataLayer, which is the point of preserveBehavior. The fallback then deletes window.dataLayer. GTM runs again on the main thread starting from an empty array, so everything pushed before it is lost (consent defaults, page data, early events).
Follow-up to #596, as requested in #596 (comment). I'd like to submit a PR for this.
Open the reproduction. swPath points to a missing file, so the service worker never registers and the fallback runs after fallbackTimeout: 500.
Two entries are pushed into dataLayer before the fallback.
A text/partytown script, standing in for the GTM snippet, records what's in window.dataLayer when it runs on the main thread.
Expected: entriesSeenByGtm contains the 2 entries pushed before the fallback.
Actual: entriesSeenByGtm is []. ga, forwarded without preserveBehavior, is deleted as expected.
Browser Info
Chrome 155, macOS. Partytown 1.0.0, service worker mode. The fallback code doesn't depend on the browser.
Additional Information
Proposed fix: in fallback(), don't delete a top-level object when a nested property under it is forwarded with preserveBehavior (keep dataLayer for dataLayer.push). Top-level stubs like fbq should still be deleted so their snippet can set them up again. We currently ship this as a pnpm patch.
Activity
ArmenMesropyanOptimax commentedon Oct 14, 2026
@gioboa Hi! Can you please take a look? 馃檹
Also I have raised a PR #790