@@ -7,6 +7,10 @@ var amy_process_single_midi_byte = null;
77var audio_started = false ;
88var amy_sysclock = null ;
99var amyboard_started = false ;
10+ // Deep-link guard: set in start_amyboard() when the initial URL has ?env=... ,
11+ // read later in start_audio() after check_url_env_params() has mutated the URL.
12+ // Keeps the default run_sketch() path from racing the deferred world-load.
13+ var _url_env_pending = false ;
1014var amy_yield_patch_events = null ;
1115var amy_yield_synth_commands = null ;
1216var amy_dump_state_to_string_c = null ;
@@ -4437,8 +4441,11 @@ async function start_amyboard() {
44374441
44384442 // Load sketch.py into the editor so the user can see/edit it before clicking to start audio.
44394443 // The actual run_sketch() (applying knobs + starting loop) is deferred to start_audio().
4440- var urlEnvPending = ! ! ( new URLSearchParams ( window . location . search ) . get ( "env" ) ) ;
4441- if ( ! urlEnvPending ) {
4444+ // Use a persistent module-level flag (set before check_url_env_params mutates
4445+ // window.location.search) so start_audio() later still knows the deep-link
4446+ // sketch is pending and doesn't race a default run_sketch() against it.
4447+ _url_env_pending = ! ! ( new URLSearchParams ( window . location . search ) . get ( "env" ) ) ;
4448+ if ( ! _url_env_pending ) {
44424449 var _pendingSketch = "" ;
44434450 try { _pendingSketch = mp . FS . readFile ( CURRENT_ENV_DIR + '/sketch.py' , { encoding : 'utf8' } ) ; } catch ( e ) { }
44444451 if ( ! _pendingSketch ) _pendingSketch = _get_default_sketch ( ) ;
@@ -4498,8 +4505,11 @@ async function start_audio() {
44984505
44994506 // Audio is now running and AMY can process messages — run sketch.py the same
45004507 // way hardware does: apply _auto_generated_knobs, import sketch.py, start loop().
4501- var urlEnvPending = ! ! ( new URLSearchParams ( window . location . search ) . get ( "env" ) ) ;
4502- if ( mp && ! urlEnvPending ) {
4508+ // Read the persistent flag (set in start_amyboard before check_url_env_params
4509+ // cleared the URL query string) — do NOT re-parse window.location.search here,
4510+ // it's been mutated by that point and would falsely return false, causing us
4511+ // to race a default run_sketch() against check_url_env_params's deferred load.
4512+ if ( mp && ! _url_env_pending ) {
45034513 // Init synth 1 with default Juno patch before run_sketch applies knobs.
45044514 // On main, restore_patch_state_from_files did this. Without it, synth 1
45054515 // doesn't exist and _apply_knobs_text fails with "synth not defined".
0 commit comments