Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add dynamic module loader to flutter wasm entrypoint script.
  • Loading branch information
natebiggs committed May 27, 2025
commit 97507af3fdd9a864b93ca3237fae926af8c7e602
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,17 @@ export class FlutterEntrypointLoader {
importsPromise = Promise.resolve({});
}
const compiledDartApp = await compiledDartAppPromise;
const dartApp = await compiledDartApp.instantiate(await importsPromise);
const dartApp = await compiledDartApp.instantiate(await importsPromise, {
loadDynamicModule: async (wasmUri, mjsUri) => {
const wasmBytes = fetch(resolveUrlWithSegments(wasmUri));
let mjsRuntimeUri = resolveUrlWithSegments(entrypointBaseUrl, mjsUri);
Comment on lines +178 to +180
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some documentation about this that I can look at? I'm trying to understand why mjsUri is prefixed by entrypointBaseUrl but not wasmUri.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out, thanks! During local testing this worked without that but the paths are probably simpler in that environment.

I went ahead and added the entrypointBaseUrl since the URL generated should have the same format as that of the main module which also uses entrypointBaseUrl.

Documentation on this input here: https://github.com/dart-lang/sdk/blob/main/pkg/dart2wasm/lib/js/runtime_blob.dart#L54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay, that makes more sense :)

Thanks for the link!

if (this._ttPolicy != null) {
mjsRuntimeUri = this._ttPolicy.createScriptURL(mjsRuntimeUri);
}
const mjsModule = import(mjsRuntimeUri);
return [await wasmBytes, await mjsModule];
}
});
await dartApp.invokeMain();
}
}
Expand Down