editor icon indicating copy to clipboard operation
editor copied to clipboard

fix(editor): polyfill structuredClone for legacy browsers (Sentry MONOREPO-EDITOR-FB)

Open anton-pascal opened this issue 4 months ago • 0 comments

Summary

  • add a guarded structuredClone polyfill for browsers that do not provide the native API
  • load it from Next.js instrumentation-client.ts before the editor's client modules are evaluated
  • add a local TypeScript declaration for @ungap/structured-clone

Sentry issue

Sentry issue MONOREPO-EDITOR-FB shows the public viewer failing entirely on legacy Android browsers (including Honor Browser 9.8.0 / Chromium <98) with ReferenceError: structuredClone is not defined.

@pascal-app/[email protected] calls structuredClone during module initialization through registerKind. The package is imported by packages/editor/src/lib/measurement-parser.ts, so app-level component guards run too late. Installing the global fallback from the client instrumentation entry ensures it exists before the editor/lingo module graph is evaluated.

Validation

  • bun install --frozen-lockfile ✅
  • Biome lint on the new instrumentation/polyfill/type declaration files ✅
  • editor app typecheck: touched files pass, but the command remains red due to existing unrelated workspace type/export mismatches

Generated from the nightly Sentry triage cron.


[!NOTE] Low Risk Small, guarded client bootstrap change with a well-known polyfill; native browsers are untouched and scope is limited to the editor app.

Overview Fixes hard crashes on legacy browsers (e.g. older Android / Chromium <98) where structuredClone is missing and the editor fails during module load (Sentry MONOREPO-EDITOR-FB).

The editor app now depends on @ungap/structured-clone and installs a guarded global fallback in lib/polyfills/structured-clone.ts (only when globalThis.structuredClone is not a function). That polyfill is pulled in from instrumentation-client.ts so it runs before the rest of the client bundle—important because dependencies such as @pascal-app/lingo can call structuredClone at import time.

A local ungap-structured-clone.d.ts types the polyfill package for TypeScript.

Reviewed by Cursor Bugbot for commit e380b05bb2d2cf454f634df8e3b919c108b23b0a. Bugbot is set up for automated code reviews on this repo. Configure here.

anton-pascal avatar Jul 21 '26 04:07 anton-pascal