Skip to content

Add host-controlled script loading for bundled imports - #259

Open
bghgary wants to merge 2 commits into
BabylonJS:mainfrom
bghgary:bghgary-support-dynamic-imports-embedded
Open

bghgary wants to merge 2 commits into
BabylonJS:mainfrom
bghgary:bghgary-support-dynamic-imports-embedded

Conversation

@bghgary

@bghgary bghgary commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

[Created by Copilot on behalf of @bghgary]

Context

Hosts that package JavaScript as resources need to load deferred bundles without enabling unrestricted file or network access. Resource delivery may be immediate or asynchronous.

Compatibility

The runtime API evaluates classic scripts and is independent of the bundler; it does not add native ECMAScript module loading. Source-level import() must be transformed by the bundler. See Plugins/DynamicScriptLoader/README.md for host integration and a Webpack 5 configuration example.

Browser builds keep their normal chunk transport. The Webpack example is for packaged JavaScript chunks, not a development server or hot module replacement.

@bghgary

bghgary commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

[Commented by Copilot on behalf of @bghgary]

Closing while we reconsider the API. This proposal mixes host script loading with a Web Worker-specific compatibility shim without defining how dynamic imports should work across the supported engines.

@bghgary bghgary closed this Sep 29, 2026
Expose _native.loadScript with a host resolver for immediate or asynchronous script resources, without a file or network fallback. Document a Webpack 5 configuration that waits for both chunk registration and host evaluation using Webpack's existing import promises.

Create deferred promises only for rejected loader calls to avoid retaining unused promises during runtime shutdown.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@bghgary bghgary reopened this Oct 12, 2026
@bghgary
bghgary force-pushed the bghgary-support-dynamic-imports-embedded branch from 08b5254 to f22548e Compare October 12, 2026 21:43
@bghgary

bghgary commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

[Commented by Copilot on behalf of @bghgary]

Reopening with the host-controlled script loader and a documented Webpack 5 example. The worker-specific importScripts API is no longer part of this proposal.

@bghgary bghgary changed the title Add resolver-backed dynamic script loading Add host-controlled script loading for bundled imports Oct 12, 2026
@bghgary
bghgary marked this pull request as ready for review October 12, 2026 21:48
@bghgary
bghgary requested review from ryantrem and a balanced review from Copilot October 12, 2026 21:48

Copilot AI left a comment

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.

🟡 Changes recommended

The new tests are omitted from Android’s separately maintained UnitTestsJNI target.

1 open finding
What changed in this PR

Adds an optional host-controlled loader for evaluating bundled JavaScript resources without filesystem or network access.

Changes:

  • Adds _native.loadScript with synchronous and asynchronous resolvers.
  • Adds validation, error handling, tests, and CMake integration.
  • Documents host usage and Webpack 5 chunk loading.
File Description
CMakeLists.txt Adds the plugin option and directory.
Plugins/​CMakeLists.txt Conditionally enables the plugin.
Plugins/​DynamicScriptLoader/​CMakeLists.txt Defines the plugin library.
Plugins/​DynamicScriptLoader/​Include/​Babylon/​Plugins/​DynamicScriptLoader.h Declares the resolver API.
Plugins/​DynamicScriptLoader/​Source/​DynamicScriptLoader.cpp Implements script resolution and evaluation.
Plugins/​DynamicScriptLoader/​README.md Documents usage and Webpack integration.
Tests/​UnitTests/​CMakeLists.txt Registers desktop tests.
Tests/​UnitTests/​Source/​Tests.DynamicScriptLoader.cpp Tests loading, validation, and errors.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Tests/UnitTests/CMakeLists.txt
Use the supported named-property check to preserve an existing loadScript entry. HasOwnProperty misses duplicates on JavaScriptCore and is unimplemented on JSI.

Include the loader tests and conditional library dependency in Android's separately executed UnitTestsJNI target.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants