From bf9c4e9a3ed37e505c62cf63d1770c66cdf6614f Mon Sep 17 00:00:00 2001 From: Charles Ancheta <55412395+cbebe@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:31:56 -0600 Subject: [PATCH] website: Add baseURL to web-interpreter-opt.wasm --- pkg/website/src/components/Interpreter/FyshWrapper.ts | 4 ++-- pkg/website/src/components/Interpreter/Interpreter.tsx | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/website/src/components/Interpreter/FyshWrapper.ts b/pkg/website/src/components/Interpreter/FyshWrapper.ts index 9612335..9739d43 100644 --- a/pkg/website/src/components/Interpreter/FyshWrapper.ts +++ b/pkg/website/src/components/Interpreter/FyshWrapper.ts @@ -20,7 +20,7 @@ export default class FyshWrapper { constructor(private onPrintOut: OutputFunc, private onPrintError: OutputFunc) {} - public async initialize(): Promise { + public async initialize(baseURL: string): Promise { this.go = new Go(); this.go.importObject['main.go.printError'] = (addr: number, length: number) => { this.onPrintOut(this.logText(addr, length)); @@ -32,7 +32,7 @@ export default class FyshWrapper { printError: this.go.importObject['main.go.printError'], printOut: this.go.importObject['main.go.printOut'], }; - const WASM_URL = '/web-interpreter-opt.wasm'; + const WASM_URL = baseURL + 'web-interpreter-opt.wasm'; const obj = 'instantiateStreaming' in WebAssembly ? await WebAssembly.instantiateStreaming(fetch(WASM_URL), this.go.importObject) diff --git a/pkg/website/src/components/Interpreter/Interpreter.tsx b/pkg/website/src/components/Interpreter/Interpreter.tsx index 9e7e258..b7dcd31 100644 --- a/pkg/website/src/components/Interpreter/Interpreter.tsx +++ b/pkg/website/src/components/Interpreter/Interpreter.tsx @@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useState } from 'react'; import { exampleFactorial } from './factorial'; import FyshWrapper from './FyshWrapper'; import styles from './Interpreter.module.css'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; function useScript(script: string) { const [loaded, setLoaded] = useState(false); @@ -19,6 +20,7 @@ function useScript(script: string) { } export default function Interpreter() { + const context = useDocusaurusContext(); const [input, setInput] = useState(exampleFactorial); const [output, setOutput] = useState(''); const isBrowser = useIsBrowser(); @@ -35,7 +37,7 @@ export default function Interpreter() { let mounted = true; if (isBrowser && loadedWasm) { const fysh = new FyshWrapper(printOutput, printOutput); - fysh.initialize().then(() => { + fysh.initialize(context.siteConfig.baseUrl).then(() => { if (mounted) { setFysh(fysh); } @@ -44,7 +46,7 @@ export default function Interpreter() { return () => { mounted = false; }; - }, [isBrowser, loadedWasm]); + }, [isBrowser, loadedWasm, context.siteConfig.baseUrl]); function runFysh() { setOutput('');