Skip to content

Commit

Permalink
website: Add baseURL to web-interpreter-opt.wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
cbebe committed Oct 19, 2024
1 parent d39dd34 commit bf9c4e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/website/src/components/Interpreter/FyshWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class FyshWrapper {

constructor(private onPrintOut: OutputFunc, private onPrintError: OutputFunc) {}

public async initialize(): Promise<void> {
public async initialize(baseURL: string): Promise<void> {
this.go = new Go();
this.go.importObject['main.go.printError'] = (addr: number, length: number) => {
this.onPrintOut(this.logText(addr, length));
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/website/src/components/Interpreter/Interpreter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -44,7 +46,7 @@ export default function Interpreter() {
return () => {
mounted = false;
};
}, [isBrowser, loadedWasm]);
}, [isBrowser, loadedWasm, context.siteConfig.baseUrl]);

function runFysh() {
setOutput('');
Expand Down

0 comments on commit bf9c4e9

Please sign in to comment.