Skip to content

Commit 6b7641b

Browse files
yash-prolytechyash04577
authored andcommitted
fix(snack-player): downscope observer to .container and use querySelectorAll
1 parent 9d5e577 commit 6b7641b

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

website/modules/snackPlayerInitializer.js

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

68+
const setupSnackObserver = () => {
69+
const targetContainer =
70+
document.querySelector('.container') || document.body;
71+
72+
const observer = new MutationObserver(() => {
73+
const snacks = targetContainer?.querySelectorAll('.snack-player');
74+
if (snacks.length && window.ExpoSnack) {
75+
updateSnacksTheme();
76+
window.ExpoSnack.initialize();
77+
}
78+
});
79+
80+
observer.observe(targetContainer, {
81+
childList: true,
82+
subtree: true,
83+
});
84+
};
85+
6886
// Need to set the theme before the snack script (deferred) initialize
6987
updateSnacksTheme();
88+
setupSnackObserver();
7089
setupThemeSynchronization();
7190

7291
return {

0 commit comments

Comments
 (0)