Fix Snack player initialization race condition#4870
Conversation
|
Hi @yash04577! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ Deploy Preview for react-native ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
cabacd7 to
6b7641b
Compare
|
Made the requested changes:
@Simek updated as per your feedback. Thanks for the review! 🙌 |
|
Thanks for the quick updates @yash04577! 👍 Hmm, it looks like after the recent change the problem is back on the PR preview deployment. Earlier it was working as described in the main PR comment. Can you look at it?
|
|
Hi @Simek , I’ve pushed an update that fixes the issue. Please take a look when you have a moment. |
Simek
left a comment
There was a problem hiding this comment.
Thanks for the fix! Retested website with latest changes, LGTM! 🚀
|
I just pulled the latest main but I'm getting an error from this part: observer.observe(document.querySelector('.container'), {Apparently |
|
Hey @pooriamo, nice catch, thanks for pointing this out! 🙏 Will merge the fix soon. |

Snack players were sometimes not initializing on first load or when added dynamically (e.g. in tabs or via MDX). This was due to
ExpoSnack.initialize()being called before the deferredembed.jsscript finished loading.Reproduction Steps (Before Fix)
Ctrl+Shift+R)https://reactnative.dev/docs/flatlistOld Behavior (Buggy)
*(Hard refresh → blank Snack → needs tab switch)*New Behavior (Fixed)
*(Hard refresh → Snack loads instantly)*Root Cause
ExpoSnack.initialize()was called too early — before thedeferredembed.jsscript loadedFix
embed.jsto load before callinginitialize()script.addEventListener('load', ...)— no polling, no timeoutMutationObserverondocument.bodycatches all new.snack-playerelements