File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments