Use native fetch() polyfill from JsRuntimeHost in Playground#1707
Use native fetch() polyfill from JsRuntimeHost in Playground#1707bkaradzic-microsoft wants to merge 1 commit into
Conversation
ryantrem
left a comment
There was a problem hiding this comment.
Similar question as the other PR - should we just add a full native fetch polyfill? Maybe we could add it to XMLHttpRequest (@bghgary might say no though 😅), or a new polyfill. It would be good to have this in BN anyway so the BJS codebase can use fetch rather than XMLHttpRequest.
bghgary
left a comment
There was a problem hiding this comment.
[Reviewed by Copilot on behalf of @bghgary]
Same as #1700 and #1706 — fetch is a standard web API that Babylon.js code paths depend on. Should be a proper C++ polyfill under Polyfills/, not a Playground-only JS script. See BabylonJS/JsRuntimeHost#98.
Per-test PIL-composite triage of all 17 ``subtle pixel-diff`` tests. None of them are deterministic-cosmetic (no re-bakes possible - all show real visible regressions). Updates the `reason` field in `Apps/Playground/Scripts/config.json` for 17 tests with accurate symptom descriptions, classifying into recurring root-cause clusters: - 9 GUI green->red color regressions (idx 160, 174, 175, 196, 197, 370, 402, 566, 587) - 4 OpenPBR analytic-lights right-column red rendering (580, 584, 587, 592) - 1 instanced billboard foliage red (169) - 1 LineEdgesRenderer extra red lines (179) - 1 Background blur red splotches (602) - 1 Clip planes GUI sliders red (182) - 1 Instanced Bones edge-AA (256, borderline) **No source changes, no test re-enables, no PNGs.** Metadata-only correction so the issue tracker reflects actionable root causes. --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**.
Per-test triage of 5 post-#1695 pixel-diff fallouts. Updates the `reason` field in `Apps/Playground/Scripts/config.json` for 3 entries to name the real BN rendering regression instead of generic "Pixel comparison fails": - idx 363 SSR2 - SSR not rendering wet floor. - idx 369 Sprites Pixel Perfect - sprite alpha-blending broken. - idx 395 soft-transparent-shadows - soft-shadow filter precision degraded. **No source changes, no test re-enables, no PNGs.** Metadata-only correction so the issue tracker reflects actionable root causes for follow-up engineering work. --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**.
…1703) Fixes MSVC C4702 (unreachable code) under `/WX` in `Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp` so the OpenGL TU builds cleanly without the project-wide `/wd4702` workaround. ## What changed `Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp` keeps the unimplemented `Impl` stubs as `throw std::runtime_error{"not implemented"}` (so callers get an unambiguous diagnostic matching every other backend's unimplemented path) and wraps the `#include "ExternalTexture_Shared.h"` line in `#pragma warning(push)/(disable: 4702)/(pop)`. The shared dispatchers instantiated by that include unconditionally call the stubs, so MSVC's flow analysis flags the dispatcher's post-call code as unreachable; the pragma suppresses C4702 only for the dispatcher code instantiated in this translation unit. Any other code in this file is still subject to `/WX` C4702 enforcement. `Plugins/ExternalTexture/CMakeLists.txt` - drop the `/wd4702` target compile option, which previously silenced C4702 across the whole target. ## Alternatives considered - **`[[noreturn]]` on the stubs**: MSVC propagates "never returns" through the shared dispatcher, which flags *more* post-call statements as unreachable. Tried and rejected (it made the warning worse). - **TU-wide `/wd4702` via `target_compile_options`**: silences any future legitimate C4702 elsewhere in the same TU, defeating `/WX`. The current localized `#pragma warning(push/pop)` block keeps the rest of the TU under `/WX` enforcement. - **Replacing the throws with inert return-default stubs**: changes product behaviour (callers would silently receive a null texture instead of a clear "not implemented" error) to work around a compiler warning. Rejected on principle. ## Verified Clean under Debug + Release + RelWithDebInfo on OpenGL (`win32-gl`, `GRAPHICS_API=OpenGLWindowsDevOnly`) and D3D11 (`win32`). --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks @bghgary @ryantrem — agreed. Same pivot pattern as #1706/#1708: this will move to a native polyfill under Plan:
Parking this PR until step 2 lands; will convert to draft. The current JS-shim diff is superseded and not worth re-reviewing. |
…BJ tests) (#1706) Re-enables the 19 GLTF/OBJ serializer round-trip tests that fail under BN today because the runtime is missing `File` and `FileReader`. Babylon.js code paths (`new File([blob], 'scene.glb')` followed by `LoadAssetContainerAsync(file, scene)`, which internally reads via `FileReader.readAsArrayBuffer`) need both APIs to work. The actual polyfill **lives in JsRuntimeHost** ([bkaradzic-microsoft/JsRuntimeHost @ 670084e5](bkaradzic-microsoft/JsRuntimeHost@670084e)), next to `Polyfills/Blob/`. That's the architecturally correct home — `File` and `FileReader` are standard WHATWG web APIs in the same category as the existing `XMLHttpRequest` / `URL` / `WebSocket` / `TextDecoder` / `AbortController` polyfills hosted there, and `File` is layered directly on top of `Blob`. Hosting them there means every JsRuntimeHost consumer (BN and any other embedder) gets them. > Addresses [@bghgary's review](#1706 (review)): _"this should be a proper C++ polyfill under `Polyfills/` so every consumer gets it, not a Playground-only JS script"_. **This PR (BN-side) is intentionally tiny:** - `CMakeLists.txt` — bump JsRuntimeHost `GIT_TAG` to `670084e5` and temporarily point `GIT_REPOSITORY` at the [`bkaradzic-microsoft/JsRuntimeHost`](https://github.com/bkaradzic-microsoft/JsRuntimeHost) fork until the upstream JsRuntimeHost PR is merged. Will be re-pinned to a `BabylonJS/JsRuntimeHost` commit before this PR merges. - `Apps/Playground/Shared/AppContext.cpp` — `Babylon::Polyfills::File::Initialize(env)` immediately after `Blob::Initialize(env)`. The old `LoadScript("app:///Scripts/file_polyfill.js")` line is gone. - `Apps/Playground/CMakeLists.txt` — drops `file_polyfill.js` from SCRIPTS, links the new JsRuntimeHost `File` target into the Playground binary. - `Apps/Playground/Scripts/file_polyfill.js` — deleted (308 lines of JS subsumed by the C++ polyfill in JsRuntimeHost). - `Apps/Playground/Scripts/config.json` — re-enables 19 affected tests; adds `excludedGraphicsApis: ["OpenGL"]` to 5 GLTF Serializer tests (KHR gpu instancing + 4 Camera variants) for OpenGL-specific backend issues unrelated to this polyfill. **Verified:** 19/19 affected tests pass on Win32 D3D11 Release headless without `--include-excluded` (indices 208-216, 219-226, 275-276). Remaining 9 (in the same family) fail with separate root causes — tracked separately. ## Landing sequence 1. ✅ Push JsRuntimeHost work to fork branch + this BN PR (← here, validating CI against fork branch). 2. ⏳ Open PR to `BabylonJS/JsRuntimeHost` adding `Polyfills/File/` once BN CI is green here. 3. ⏳ After the JsRuntimeHost PR merges, re-pin this BN PR's `GIT_REPOSITORY` / `GIT_TAG` back to `BabylonJS/JsRuntimeHost` at the merged SHA. 4. ⏳ Merge this BN PR. --- ## Series landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/FileReader polyfill (JsRuntimeHost bump + Playground wiring; largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com>
b32bf39 to
c2d8675
Compare
Replaces the JS XMLHttpRequest-based fetch shim with the native fetch() polyfill that landed in JsRuntimeHost (PR BabylonJS#188). AppContext now calls Babylon::Polyfills::Fetch::Initialize(env) alongside the other polyfills, and Playground links the Fetch target. Removes Apps/Playground/Scripts/fetch_polyfill.js and its SCRIPTS / script loader entries. Bumps the JsRuntimeHost pin to pick up the native polyfill. NOTE: the JsRuntimeHost pin temporarily points at the PR BabylonJS#188 branch (bkaradzic-microsoft/JsRuntimeHost@1118799); switch it back to a BabylonJS/JsRuntimeHost commit once BabylonJS#188 merges. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c2d8675 to
14afc73
Compare
Wires Babylon Native''s Playground up to the native
fetch()polyfill that now lives in JsRuntimeHost (BabylonJS/JsRuntimeHost#188), so playgrounds depending onfetchstop hittingReferenceError: ''fetch'' is not defined.This supersedes the original JS XMLHttpRequest-based shim approach: rather than shipping a
fetch_polyfill.jsscript,fetchis now provided natively (built on the sameUrlLibtransport asXMLHttpRequest), matching how File/FileReader landed in #1706.Changes:
Apps/Playground/Shared/AppContext.cpp- callsBabylon::Polyfills::Fetch::Initialize(env)alongside the other polyfills (right afterXMLHttpRequest).Apps/Playground/CMakeLists.txt- links theFetchtarget; dropsfetch_polyfill.jsfrom the SCRIPTS list.Apps/Playground/Scripts/fetch_polyfill.jsand its script-loader entry.CMakeLists.txt- bumps the JsRuntimeHost pin to pick up the native polyfill.Verified:
Playgroundtarget configures, builds and links cleanly (Win32/Chakra) against the native polyfill.Landing context
This PR is one of the splits from the proven CI-green combined preview in draft PR #1702 (see #1702 for the full intended end-state).
Landing order / status
Tier 1 - parallel-reviewable, no source conflicts:
Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX #1703 - ExternalTexture C4702 build fix✅ mergedDocument accurate root cause for post-#1695 pixel-diff fallouts #1704 - config.json✅ mergedreasonrewrites (5 entries)Document accurate root cause for 17 subtle pixel-diff tests #1705 - config.json✅ mergedreasonrewrites (17 entries)Tier 2 - sequential, each touches
Apps/Playground/CMakeLists.txt+AppContext.cpp:Bump JsRuntimeHost for File/FileReader polyfill (re-enables 19 GLTF/OBJ tests) #1706 - File/FileReader polyfill✅ merged (native JsRuntimeHost bump)Reference policy reminder
Reference PNGs come from Babylon.js; never re-baked by BN. Combined diff: 0 PNGs.