|
624 | 624 | wasmLoading = true; |
625 | 625 |
|
626 | 626 | // WASM path varies by build type: |
627 | | - // - Production/Netlify: /blobl.wasm (site root) - try first to avoid 404 in console |
| 627 | + // - Production/Netlify: /blobl.wasm (site root) |
628 | 628 | // - UI Preview (local dev): /_/blobl.wasm |
| 629 | + // Use isUiPreview variable set in head-scripts.hbs to determine correct path |
629 | 630 | const rootPath = typeof uiRootPath !== 'undefined' ? uiRootPath : '/_'; |
630 | 631 | const siteRoot = typeof siteRootPath !== 'undefined' ? siteRootPath : ''; |
631 | | - const wasmPaths = [ |
632 | | - siteRoot + '/blobl.wasm', |
633 | | - rootPath + '/blobl.wasm' |
634 | | - ]; |
| 632 | + const isPreview = typeof isUiPreview !== 'undefined' ? isUiPreview : false; |
| 633 | + |
| 634 | + // Select the correct path based on environment - no fallback to avoid 404s |
| 635 | + const wasmPath = isPreview ? rootPath + '/blobl.wasm' : siteRoot + '/blobl.wasm'; |
635 | 636 |
|
636 | 637 | wasmLoadPromise = new Promise((resolve, reject) => { |
637 | 638 | loadRequiredScripts() |
|
641 | 642 | return; |
642 | 643 | } |
643 | 644 |
|
644 | | - // Try each path until one works |
645 | | - function tryLoadWasm(paths) { |
646 | | - if (paths.length === 0) { |
647 | | - reject(new Error('WASM file not found')); |
648 | | - return; |
649 | | - } |
650 | | - |
651 | | - const wasmPath = paths[0]; |
652 | | - const go = new Go(); |
653 | | - |
654 | | - fetch(wasmPath) |
655 | | - .then((response) => { |
656 | | - if (!response.ok) { |
657 | | - throw new Error('HTTP ' + response.status); |
658 | | - } |
659 | | - const responseClone = response.clone(); |
660 | | - return WebAssembly.instantiateStreaming(response, go.importObject) |
661 | | - .catch(async () => { |
662 | | - const bytes = await responseClone.arrayBuffer(); |
663 | | - return WebAssembly.instantiate(bytes, go.importObject); |
664 | | - }); |
665 | | - }) |
666 | | - .then((result) => { |
667 | | - go.run(result.instance); |
668 | | - wasmLoaded = true; |
669 | | - wasmLoading = false; |
670 | | - resolve(); |
671 | | - }) |
672 | | - .catch(() => { |
673 | | - // Try next path |
674 | | - tryLoadWasm(paths.slice(1)); |
675 | | - }); |
676 | | - } |
677 | | - |
678 | | - tryLoadWasm(wasmPaths); |
| 645 | + const go = new Go(); |
| 646 | + fetch(wasmPath) |
| 647 | + .then((response) => { |
| 648 | + if (!response.ok) { |
| 649 | + throw new Error('WASM file not found at ' + wasmPath); |
| 650 | + } |
| 651 | + const responseClone = response.clone(); |
| 652 | + return WebAssembly.instantiateStreaming(response, go.importObject) |
| 653 | + .catch(async () => { |
| 654 | + const bytes = await responseClone.arrayBuffer(); |
| 655 | + return WebAssembly.instantiate(bytes, go.importObject); |
| 656 | + }); |
| 657 | + }) |
| 658 | + .then((result) => { |
| 659 | + go.run(result.instance); |
| 660 | + wasmLoaded = true; |
| 661 | + wasmLoading = false; |
| 662 | + resolve(); |
| 663 | + }) |
| 664 | + .catch(reject); |
679 | 665 | }) |
680 | 666 | .catch(reject); |
681 | 667 | }); |
|
0 commit comments