Skip to content

Commit 621ebe5

Browse files
Use native fetch() polyfill from JsRuntimeHost in Playground (#1707)
Wires Babylon Native's Playground up to the **native `fetch()` polyfill** that now lives in JsRuntimeHost (BabylonJS/JsRuntimeHost#188), so playgrounds depending on `fetch` stop hitting `ReferenceError: 'fetch' is not defined`. This supersedes the original JS XMLHttpRequest-based shim approach: rather than shipping a `fetch_polyfill.js` script, `fetch` is now provided natively (built on the same `UrlLib` transport as `XMLHttpRequest`), matching how File/FileReader landed in #1706. **Changes:** - `Apps/Playground/Shared/AppContext.cpp` - calls `Babylon::Polyfills::Fetch::Initialize(env)` alongside the other polyfills (right after `XMLHttpRequest`). - `Apps/Playground/CMakeLists.txt` + `Apps/Playground/Android/BabylonNative/CMakeLists.txt` - link the `Fetch` target. - `CMakeLists.txt` - bumps the JsRuntimeHost pin to pick up the native polyfill. > ✅ **Unblocked:** JsRuntimeHost#188 merged, and the pin now points at `BabylonJS/JsRuntimeHost@a407a331` (the #188 merge commit) — no longer the temporary fork branch. Rebased onto master (clean). **Verified (Win32/Chakra):** `Playground` configures, builds and links cleanly against the native polyfill, and at runtime `typeof fetch === "function"` (confirmed via a headless smoke check). --- ## Landing context This PR is one of the **splits** from the proven CI-green combined preview in draft PR #1702 (see [#1702](#1702) for the full intended end-state). > The original split also included #1709 (ES2020+ -> ES2019 syntax-repair polyfill for Chakra), closed in favour of investigating `@babel/standalone` properly (#1711). ### Landing order / status **Tier 1 - parallel-reviewable, no source conflicts:** 1. ~~#1703 - ExternalTexture C4702 build fix~~ ✅ merged 2. ~~#1704 - config.json `reason` rewrites (5 entries)~~ ✅ merged 3. ~~#1705 - config.json `reason` rewrites (17 entries)~~ ✅ merged **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` + `AppContext.cpp`:** 4. ~~#1706 - File/FileReader polyfill~~ ✅ merged (native JsRuntimeHost bump) 5. **#1707 - native fetch polyfill (this PR)** - ✅ unblocked; pin repointed to `BabylonJS/JsRuntimeHost@a407a331`; ready for review 6. #1708 - link AbortController + TextEncoder polyfills from JsRuntimeHost 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0af8463 commit 621ebe5

4 files changed

Lines changed: 5 additions & 1 deletion

File tree

Apps/Playground/Android/BabylonNative/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ target_link_libraries(BabylonNativeJNI
3030
PRIVATE Blob
3131
PRIVATE Canvas
3232
PRIVATE Console
33+
PRIVATE Fetch
3334
PRIVATE File
3435
PRIVATE GraphicsDevice
3536
PRIVATE NativeCamera

Apps/Playground/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ target_link_libraries(Playground
156156
PRIVATE TextDecoder
157157
PRIVATE Window
158158
PRIVATE XMLHttpRequest
159+
PRIVATE Fetch
159160
${ADDITIONAL_LIBRARIES}
160161
${BABYLON_NATIVE_PLAYGROUND_EXTENSION_LIBRARIES})
161162

Apps/Playground/Shared/AppContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <Babylon/Polyfills/Blob.h>
2121
#include <Babylon/Polyfills/Canvas.h>
2222
#include <Babylon/Polyfills/Console.h>
23+
#include <Babylon/Polyfills/Fetch.h>
2324
#include <Babylon/Polyfills/File.h>
2425
#include <Babylon/Polyfills/Performance.h>
2526
#include <Babylon/Polyfills/TextDecoder.h>
@@ -186,6 +187,7 @@ AppContext::AppContext(
186187
Babylon::Polyfills::TextDecoder::Initialize(env);
187188

188189
Babylon::Polyfills::XMLHttpRequest::Initialize(env);
190+
Babylon::Polyfills::Fetch::Initialize(env);
189191
m_canvas.emplace(Babylon::Polyfills::Canvas::Initialize(env));
190192

191193
Babylon::Plugins::NativeTracing::Initialize(env);

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ FetchContent_Declare(ios-cmake
5454
EXCLUDE_FROM_ALL)
5555
FetchContent_Declare(JsRuntimeHost
5656
GIT_REPOSITORY https://github.com/BabylonJS/JsRuntimeHost.git
57-
GIT_TAG c88625b6d61b55c4589f02408d03826e83199870)
57+
GIT_TAG 99457c03625782c3eeac6609f632538c7c9445d0)
5858
FetchContent_Declare(metal-cpp
5959
GIT_REPOSITORY https://github.com/bkaradzic/metal-cpp.git
6060
GIT_TAG metal-cpp_26

0 commit comments

Comments
 (0)