Skip to content

Remove non-erasable TypeScript syntax from Polyfill - #653

Merged
andrewiggins merged 3 commits into
mainfrom
fix-erasableSyntaxOnly-exceptions
Sep 1, 2026
Merged

andrewiggins merged 3 commits into
mainfrom
fix-erasableSyntaxOnly-exceptions

Conversation

@andrewiggins

@andrewiggins andrewiggins commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@remote-dom/polyfill was the last project in this repo that didn't support erasableSyntaxOnly without exceptions. This PR removes those exceptions.

It turns out that our babel transform turned these const enums into full TS enums even though we didn't use them as such. These data structures cost us 1.5kb in a minified build. So I've replaced the const enums with just const variables. These enums were never exported publically so it shouldn't be a breaking change. It also more closely matches the DOM which just uses raw numbers here anyway.

What changed

  • replace the Polyfill's TypeScript parameter property with an explicit field assignment
  • replace five const enum declarations with erasable scalar constants
  • preserve publicly reachable numeric fields as number and namespace values as a string-literal union
  • add coverage for observable event, node type, and namespace behavior
  • add a patch changeset for @remote-dom/polyfill

Every TypeScript project now enables erasableSyntaxOnly without syntax-related suppression comments.

ESM bundle size

Measured by bundling and minifying the public Window export with esbuild 0.25.12:

Metric Before After Change
Minified 22,282 B 20,742 B -1,540 B
Gzip 7,516 B 7,167 B -349 B
Brotli 6,710 B 6,383 B -327 B

Testing

  • pnpm exec tsc --build --pretty --force
  • pnpm exec vitest run
  • pnpm build
  • pnpm lint
  • pnpm exec playwright test --workers=1
  • direct execution of the Polyfill source with Node type stripping

Replace internal constant objects with scalar bindings so bundlers can eliminate unused values and avoid materializing lookup maps.

Minified ESM Window bundle versus 1aacf66 (esbuild 0.25.12):
- minified: 21,518 B -> 20,742 B (-776 B)
- gzip: 7,321 B -> 7,167 B (-154 B)
- Brotli: 6,564 B -> 6,383 B (-181 B)
@andrewiggins
andrewiggins force-pushed the fix-erasableSyntaxOnly-exceptions branch from aa5d729 to 67552cc Compare September 1, 2026 14:59
@andrewiggins
andrewiggins merged commit a9aee3e into main Sep 1, 2026
9 checks passed
@andrewiggins
andrewiggins deleted the fix-erasableSyntaxOnly-exceptions branch September 1, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants