fix(browser): ship a build react-scripts 4 / webpack 4 can parse - #868
fix(browser): ship a build react-scripts 4 / webpack 4 can parse#868Bhumika-1432006 wants to merge 1 commit into
Conversation
dist/index.js compiled to the monorepo's shared ES2022 target, which meant optional chaining, nullish coalescing, and nullish-coalescing assignment (??=) went out untranspiled. react-scripts 4 / webpack 4 excludes node_modules from Babel, so any app on that stack failed to compile the moment it imported the SDK -- before a dev session could ever connect, and with no diagnostic pointing at why. packages/browser's own tsconfig.json now overrides target to ES2019, downleveling all three operators. Only this package moves; the rest of the monorepo runs on a Node version that never had this problem, so its target stays ES2022. Three test files used a BigInt literal (2n) to exercise BigInt handling in serialization -- syntax TS refuses to emit below ES2020, unrelated to whether it's downleveled. Switched to BigInt(2), same runtime value, so the lowered target can compile the whole package including its tests. Added a regression test that compiles a snippet through this package's actual tsconfig and asserts optional chaining/nullish coalescing/??= don't survive, so a future bump of the target back up fails in CI instead of in a user's silent build failure. Closes reticlehq#680. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Bhumika <guravbhumika808@gmail.com>
|
Thank you — and I am sorry, because three of us built this independently today. Closing in favour of #745, which has been open since 3 September, is fully green including both install gates, and is the most complete of the three. I wrote one of the other two (#867) and closed it for the same reason I am closing this one, so this is not a judgement about your work over mine. The gap all three of our browser-only versions share: And one thing none of us caught except #745: Your diagnosis is exactly right, including the detail that matters most: If you would like something adjacent that is genuinely open: |
|
No apology needed at all — three people converging on the same fix the same day just means the issue was well-scoped and clearly worth doing. Thanks for the detailed writeup rather than a plain "closing, see #745." The two things I missed are both real gaps in my testing, not just bad luck: I verified Glad #745 is the more complete fix and it's green on both install gates already. I'll take a look at the compiled-test-files-in-dist cleanup you mentioned — thanks for pointing at something genuinely open instead of leaving me to go looking. |
|
Looked into the compiled-test-files suggestion before opening anything, and I don't think there's a live bug here — reporting back rather than filing a no-op PR. `scripts/prepare-dist.mjs` already strips every `.test.` file (and source maps) as part of `prepack`, and every real publish path runs through it: `RELEASING.md`'s actual release step is `pnpm -r publish` (which fires `prepack` per-package), and the install gate's local-registry simulation (`apps/e2e/install-gate.mjs`) uses the exact same `pnpm -r publish --registry ... --no-git-checks` command. So `files: ["dist"]` is true, but by the time `npm pack`/`publish` actually reads that field, `prepack` has already run and `dist` is already clean. Confirmed empirically rather than just by reading the script — `npm pack @reticlehq/browser@latest --dry-run`, same for `@reticlehq/core` and `@reticlehq/react`, and none of the three currently-published tarballs contain a single `.test.` file. The bloat is real in a bare `pnpm build` output (that command alone doesn't run prepack), but that's local dist state, not what ships. If you were thinking of something I'm not seeing — a different publish path that skips lifecycle scripts, or a version predating `prepare-dist.mjs` — let me know and I'll take another look. Otherwise this one looks already handled. |
What & why
@reticlehq/browser'sdist/index.jscompiled to the monorepo's sharedES2022target, so optional chaining (?.), nullish coalescing (??), and nullish-coalescing assignment (??=) went out untranspiled — including right at the top ofindex.ts, in a line that runs unconditionally at module load (globalStore.__reticleInstance ??= new Reticle()).react-scripts4 / webpack 4 excludesnode_modulesfrom Babel, so any app still on that stack fails to even parse the SDK the moment it's imported — before a dev session can ever connect, with no diagnostic pointing at why. A maintainer had already landed the diagnostic half of this (initnow detectsreact-scripts@<5and explains what's about to happen), and narrowed the issue to exactly this remaining piece — the actual fix, calling it "a good candidate for a contributor: the change is scoped to one package's build config."What changed
packages/browser/tsconfig.jsonnow overridestargettoES2019(the sharedtsconfig.base.jsonstaysES2022for the rest of the monorepo — nothing else moves, since only this package'sdist/is parsed by an end user's own bundler rather than just Node).stores.test.ts,serialization.test.ts,transport.security.test.ts) used a BigInt literal (2n) to exercise BigInt handling in the redaction/serialization path. That's syntax TypeScript refuses to emit belowES2020— unrelated to whether it gets downleveled, BigInt precision just can't be polyfilled. Swapped forBigInt(2), same runtime value, so the whole package (tests included, sincetsc -btype-checks them underinclude) compiles under the lowered target.packages/browser/src/build-target.test.ts: it reads this package's actualtsconfig.jsonvia the TypeScript compiler API and compiles a snippet using all three operators through it, asserting none survive. This is a real regression test, not a manual check — if someone bumps the target back up later (or the shared base tsconfig changes in a way that leaks through), this fails in CI instead of in a user's silent build.Manually confirmed the built output is clean:
grep -c '?\.' dist/index.js,grep -c '??=' dist/index.jsboth come back0after a full rebuild.How it was verified
packages/browser/src/build-target.test.tswritten first against the unmodified tsconfig (targetES2022) — fails as expected, showing?./??=surviving in the compiled snippet.tsconfig.jsonchange — test goes green.tsc -b --force) — clean, anddist/index.jsverified free of all three operators by direct grep.packages/browserunit suite: 134 test files / 1271 tests, all passing (including the three BigInt-literal fixes and the new test).tsc -b --force(typecheck) — clean, no errors.eslinton every changed file — clean.prettier --checkon every changed file — clean.Gates run
pnpm lint && pnpm typecheck && pnpm test:unit(~2 min — always) — ran scoped to@reticlehq/browser: full 1271-test suite green, typecheck clean, lint clean, prettier clean.pnpm test:e2e(~8 min) — touched the tool surface,packages/core, an observer, or telemetrypnpm gate:install(~15 min) — touchedreticle init,vite-plugin,next, orbabel-pluginpnpm test:e2e:desktop(~3 min) — touchedpackages/electron,packages/tauri, or desktop capturetarget) plus test fixture syntax, no tool surface / core / telemetry / install-path / desktop code touched.Checklist
git commit -s)any, no free strings, no non-null!console.logor internal tracking codes left in the diffCHANGELOG.mdupdated under[Unreleased]Closes #680.
🤖 Generated with Claude Code