kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Provide a global polyfill set inside the sandboxed content context

Open rtibbles opened this issue 5 months ago • 1 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Sandbox handler and shim bundles (#14055) run inside the sandboxed content iframe on the alt origin, where no global core-js polyfill is applied — so Kolibri-authored sandbox code can hit missing builtins on older browsers. Apply the same skippable global polyfill as the main app (#9061) within the sandbox origin, before any handler or shim runs.

Complexity: Medium Target branch: develop

Context

  • #9061 produces a standalone, origin-shareable polyfill bundle and the feature-test loader; this reuses both on the sandbox origin.
  • #14055's SandboxEnvironment bootstraps handlers — the injection point for applying polyfills before handler/shim code.
  • Same browserslist floor and pinned core-js as the main app, from one build artifact (cross-origin caches don't dedupe, so "shared" means one artifact served on both origins, not one download).

The Change

  • Serve #9061's polyfill bundle and loader from the sandbox (alt origin) server alongside handler static files.
  • Apply the polyfill in the sandbox bootstrap before any handler or shim executes, reusing the same feature-test gate so modern browsers skip the download.

Out of Scope

  • The main-app polyfill bundle and loader themselves (#9061).
  • The sandbox handler architecture (#14055).
  • Changing the floor or pinned core-js version.

Acceptance Criteria

  • [ ] The sandbox (alt origin) server serves the polyfill bundle and loader from #9061.
  • [ ] The polyfill is applied before any sandbox handler or shim runs.
  • [ ] The sandbox uses the same core-js set as the main app, from a single build artifact.
  • [ ] A modern browser loads no polyfill in the sandbox; an older one gets patched globals before handlers run.
  • [ ] Tests cover both gate outcomes in the sandbox context.

References

  • #9061 — the polyfill bundle + loader this reuses
  • #14055 — sandbox handler architecture providing the bootstrap injection point
  • packages/kolibri-sandbox/ — SandboxEnvironment / handler bootstrap

AI usage

Drafted with Claude Code from the #9061 design discussion; reviewed and edited by me.

rtibbles avatar Jun 30 '26 05:06 rtibbles

Plan: Apply #9061's core-js polyfill bundle inside the sandbox iframe, behind the same feature-test gate, before any handler or shim runs.

  • [ ] Alt origin serves the polyfill bundle; main knows its URL
  • [ ] SandboxEnvironment applies the polyfill before the handler
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • SandboxEnvironment runs the shared gate; the loader bundle isn't mounted, as its document.write can't run after MAINREADY. If AC1 wants the loader file itself, iframe.html needs a build-time core URL and Task 2's gate wiring goes.
  • needsPolyfills lives in browserslist-config-kolibri, already a dependency of both consumers. If another home is wanted, only import paths change.
  • Handler bundles keep their per-bundle usage polyfill injection (webpack.config.plugin.js:221). If it should go, a follow-up drops the coreJs wiring and its spec.
  • A polyfill load failure reports HANDLER_ERROR and skips the handler. If it should degrade silently like the main page, createIframe catches it and continues.
  • urls.sandboxPolyfills() returns null when plugin data lacks the key. If it should throw like sandbox(), viewer specs must mock it.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Oct 24 '26 21:10 rtibblesbot