Skip to content

Fix MobX decorator incompatibility: switch to TC39 stage 3 decorators#5

Open
xrendan wants to merge 2 commits intomasterfrom
fix/tc39-decorators-mobx-compat
Open

Fix MobX decorator incompatibility: switch to TC39 stage 3 decorators#5
xrendan wants to merge 2 commits intomasterfrom
fix/tc39-decorators-mobx-compat

Conversation

@xrendan
Copy link
Member

@xrendan xrendan commented Feb 5, 2026

Summary

  • Fixed context.addInitializer is not a function runtime error caused by esbuild emitting legacy TypeScript decorators (__decorateClass) while MobX 6.15 expects TC39 stage 3 decorators
  • Changed experimentalDecorators: false in build.ts esbuild config so decorators are emitted as native TC39 syntax
  • Fixed 11 source files that mixed @decorator syntax with makeObservable(this, { annotations }) — not allowed with TC39 decorators:
    • 9 files (SelectionArray, MapChart, SlideInDrawer, Footer, StackedBarSegment, StackedBarChart, StackedDiscreteBarChart, MarimekkoChart, ExplorerDecisionMatrix): converted observable fields to @observable accessor and changed to makeObservable(this)
    • 2 files (AxisConfig, ChartDimension): used all-annotations approach to preserve Object.keys() serialization compatibility in Persistable classes

Test plan

  • All 1203 tests pass (81 test files)
  • bun run build succeeds
  • bun run typecheck passes
  • Compiled output contains no __decorateClass calls
  • Verify charts render correctly in consuming app (PopulationCharts)

🤖 Generated with Claude Code

…3 decorators

The esbuild config in build.ts was emitting legacy TypeScript decorators
(__decorateClass), but MobX 6.15 expects TC39 stage 3 decorators, causing
"context.addInitializer is not a function" at runtime.

- Set experimentalDecorators: false in build.ts esbuild config
- Fix 11 source files that mixed @decorator syntax with makeObservable
  annotation args (not allowed with TC39 decorators)
- Use @observable accessor for non-serializable classes
- Use all-annotations approach for AxisConfig/ChartDimension to preserve
  Object.keys() serialization compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add build:packages step before test step in CI so build.test.ts
  can import from dist/ (which is gitignored and not available in CI)
- Add --stats-json to storybook build so Chromatic TurboSnap can find
  preview-stats.json

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant