@@ -831,6 +831,8 @@ <h2>💡 Tips</h2>
831
831
let client = null ;
832
832
let currentPhpVersion = phpVersionSelect . value ;
833
833
let currentWpVersion = wpVersionSelect . value ;
834
+ let bootPromise = Promise . resolve ( ) ;
835
+ let runCounter = 0 ;
834
836
835
837
// Detect platform for keyboard shortcut display
836
838
const isMac = navigator . platform . toUpperCase ( ) . indexOf ( 'MAC' ) >= 0 ;
@@ -879,9 +881,9 @@ <h2>💡 Tips</h2>
879
881
option . textContent = version ;
880
882
wpVersionSelect . appendChild ( option ) ;
881
883
}
882
- // Restore selection if still available; otherwise fall back to latest
883
- wpVersionSelect . value = keys . includes ( startingWpVersion )
884
- ? startingWpVersion
884
+ // Use the requested version if available; otherwise fall back to latest
885
+ wpVersionSelect . value = keys . includes ( wpVersion )
886
+ ? wpVersion
885
887
: latest ;
886
888
} catch ( e ) {
887
889
console . warn (
@@ -892,6 +894,9 @@ <h2>💡 Tips</h2>
892
894
await client . isReady ;
893
895
await client . writeFile ( '/wordpress/code.php' , startingCode ) ;
894
896
await client . goTo ( '/code.php' ) ; // Blank document
897
+ // Sync current versions after boot to avoid unnecessary reboots on first run
898
+ currentPhpVersion = phpVersionSelect . value ;
899
+ currentWpVersion = wpVersionSelect . value ;
895
900
}
896
901
897
902
async function executeCode ( ) {
@@ -902,17 +907,25 @@ <h2>💡 Tips</h2>
902
907
// Save code, PHP version, and WordPress version to URL fragment immediately when running
903
908
saveStateToURL ( code , phpVersion , wpVersion ) ;
904
909
910
+ // Ensure initial boot finished before proceeding
911
+ await bootPromise ;
912
+
905
913
if (
906
914
phpVersion !== currentPhpVersion ||
907
915
wpVersion !== currentWpVersion
908
916
) {
909
917
currentPhpVersion = phpVersion ;
910
918
currentWpVersion = wpVersion ;
911
- await bootPlayground ( currentPhpVersion , currentWpVersion ) ;
919
+ bootPromise = bootPlayground (
920
+ currentPhpVersion ,
921
+ currentWpVersion
922
+ ) ;
923
+ await bootPromise ;
912
924
}
913
925
await client . writeFile ( '/wordpress/code.php' , code ) ;
914
- const uuid = crypto . randomUUID ( ) ;
915
- await client . goTo ( '/code.php?' + uuid ) ;
926
+ runCounter += 1 ;
927
+ const cacheBuster = 'run=' + runCounter + '-' + Date . now ( ) ;
928
+ await client . goTo ( '/code.php?' + cacheBuster ) ;
916
929
}
917
930
918
931
runBtn . addEventListener ( 'click' , executeCode ) ;
@@ -966,7 +979,7 @@ <h2>💡 Tips</h2>
966
979
}
967
980
968
981
// Initial boot
969
- bootPlayground ( currentPhpVersion , currentWpVersion ) ;
982
+ bootPromise = bootPlayground ( currentPhpVersion , currentWpVersion ) ;
970
983
</ script >
971
984
</ body >
972
985
</ html >
0 commit comments