fix: Duplicate inline A/B test scripts injected when multiple Content components render on the same page#4552
fix: Duplicate inline A/B test scripts injected when multiple Content components render on the same page#4552midhunadarvin wants to merge 2 commits intomainfrom
Conversation
|
|
View your CI Pipeline Execution ↗ for commit 795f86c
☁️ Nx Cloud last updated this comment at |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx test @e2e/gen1-next15-app |
❌ Failed | 7m 34s | View ↗ |
nx test @e2e/gen1-remix |
❌ Failed | 7m 29s | View ↗ |
nx test @e2e/gen1-react |
❌ Failed | 7m 18s | View ↗ |
nx test @e2e/sveltekit |
❌ Failed | 7m 37s | View ↗ |
nx test @e2e/gen1-next14-pages |
❌ Failed | 6m 42s | View ↗ |
nx test @e2e/react-sdk-next-pages |
❌ Failed | 6m 31s | View ↗ |
nx test @e2e/remix |
❌ Failed | 6m 13s | View ↗ |
nx test @e2e/hydrogen |
❌ Failed | 5m 49s | View ↗ |
Additional runs (38) |
❌ Failed | ... | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-05-06 05:24:30 UTC
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 795f86c. Configure here.
| !isBrowser() || | ||
| !document.querySelector(`script[data-id="${props.id}"]`) | ||
| ); | ||
| }, |
There was a problem hiding this comment.
Dedupe causes SSR hydration mismatch in React
Medium Severity
The shouldRender getter evaluates differently during SSR vs client hydration. During SSR, isBrowser() is false, so shouldRender is true and the <script> renders. During hydration, isBrowser() is true and document.querySelector finds the SSR'd script, so shouldRender becomes false — the virtual DOM has no script, but the DOM still has it. This causes a React hydration mismatch. The existing codebase carefully avoids this pattern — checkShouldRenderVariants handles it by having scripts remove themselves from the DOM before hydration (via document.currentScript?.remove()), but removeDuplicateScript intentionally keeps the first script in the DOM. The removeDuplicateScript wrapper alone already prevents duplicate execution via the window[scriptKey] flag, so the dedupe/shouldRender guard adds a hydration regression without additional functional benefit for SSR targets.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 795f86c. Configure here.



Description
Loom
Issue: https://www.loom.com/share/21d436c93fae4cc6836042fe15ca40e6
Fix: https://www.loom.com/share/8f4f24a45db3431cbc69d5bf77cc5ec1
Note
Medium Risk
Touches variant/personalization bootstrap script injection and adds DOM-based deduping, which could affect A/B test execution order across SDK targets if incorrect. Covered by new e2e assertions ensuring only one init script is present.
Overview
Prevents duplicate inline initialization scripts from being injected when multiple
Content/ContentVariantsinstances render on the same page.InlinedScriptnow supports an opt-indedupemode (skips rendering if a matchingscript[data-id]already exists), andContentVariantswraps the A/B and personalization init script strings with aremoveDuplicateScript(...)guard that removes extra tags and runs the script only once per page.E2E A/B tests were updated to assert a single
builderio-init-variants-fnsscript tag is present after navigation.Reviewed by Cursor Bugbot for commit 795f86c. Bugbot is set up for automated code reviews on this repo. Configure here.