Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: JS SDK - Wait for document.body to load #2002

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

bttf
Copy link
Contributor

@bttf bttf commented Jan 4, 2024

Features and Changes

In some cases the JS SDK will try to apply changes to document.body before it has loaded.

This leads to a broken state for the SDK and blocks experiments from running.

This PR modifies the way we mount a customers custom JS by appending the containing <script> tag to document.head instead.

Also adding docs to remind users that their custom JS will run immediately on page load and to take steps to assert the body or descendant elements exist before executing against them.

image

Error state

image

Dependencies

  • Requires publishing new version of SDK for changes to be deployed

Testing

Tested locally
https://www.loom.com/share/61700daefe224a5391986e387cdb663f
Old: https://www.loom.com/share/a64ed476288a44608c80d5dbb2236b2a

@bttf bttf changed the title Use mut obsv for custom js Bugfix: JS SDK - Wait for document.body to load Jan 4, 2024
Copy link

github-actions bot commented Jan 4, 2024

Your preview environment pr-2002-bttf has been deployed.

Preview environment endpoints are available at:

Copy link

github-actions bot commented Jan 4, 2024

Deploy preview for docs ready!

✅ Preview
https://docs-q3z0hsnhx-growthbook.vercel.app

Built with commit c760e89.
This pull request is being automatically deployed with vercel-action

@bttf bttf force-pushed the adnan/sdk-js-custom-js-fix-01 branch from 7213719 to a2522db Compare January 5, 2024 18:30
@bttf bttf unassigned jdorn Jan 5, 2024
@bttf bttf requested a review from jdorn January 5, 2024 19:10
@bttf bttf merged commit 488b6e9 into main Jan 5, 2024
6 checks passed
@bttf bttf deleted the adnan/sdk-js-custom-js-fix-01 branch January 5, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] JS SDK tries to apply DOM changes before document.body is loaded
2 participants