Skip to content

Commit cabacd7

Browse files
fix: initialize Snack players after embed script loads
1 parent 9d5e577 commit cabacd7

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

website/modules/snackPlayerInitializer.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,38 @@ export default (() => {
6565
});
6666
};
6767

68+
const setupSnackObserver = () => {
69+
const observer = new MutationObserver(mutations => {
70+
let shouldInitialize = false;
71+
72+
mutations.forEach(mutation => {
73+
mutation.addedNodes.forEach(node => {
74+
if (node.nodeType === 1) {
75+
if (
76+
node.classList?.contains('snack-player') ||
77+
node.querySelector?.('.snack-player')
78+
) {
79+
shouldInitialize = true;
80+
}
81+
}
82+
});
83+
});
84+
85+
if (shouldInitialize && window.ExpoSnack) {
86+
updateSnacksTheme();
87+
window.ExpoSnack.initialize();
88+
}
89+
});
90+
91+
observer.observe(document.body, {
92+
childList: true,
93+
subtree: true,
94+
});
95+
};
96+
6897
// Need to set the theme before the snack script (deferred) initialize
6998
updateSnacksTheme();
99+
setupSnackObserver();
70100
setupThemeSynchronization();
71101

72102
return {

0 commit comments

Comments
 (0)