Repository navigation
Stable decorators - #20868
Stable decorators#20868
Conversation
829a516 to
2dac217
Compare
Rollup was actually dropping a side-effect that was intentionally part of a test.
bee2249 to
ae9a729
Compare
Estimated Asset SizesDiff --- main/out.txt 2026-01-06 18:46:40.000000000 +0000
+++ pr/./pr-20759770739/out.txt 2026-01-06 19:35:12.000000000 +0000
@@ -1,46 +1,46 @@
╔═══════╤═══════════╤═══════════╗
║ │ Min │ Gzip ║
╟───────┼───────────┼───────────╢
-║ Total │ 352.11 KB │ 203.55 KB ║
+║ Total │ 353.32 KB │ 205.03 KB ║
╚═══════╧═══════════╧═══════════╝
-╔══════════════════════╤═══════════╤══════════╗
-║ @ember/* │ Min │ Gzip ║
-╟──────────────────────┼───────────┼──────────╢
-║ Total │ 313.81 KB │ 181.8 KB ║
-╟──────────────────────┼───────────┼──────────╢
-║ -internals │ 36.61 KB │ 26 KB ║
-║ application │ 13.24 KB │ 8.03 KB ║
-║ array │ 13.05 KB │ 7.54 KB ║
-║ canary-features │ 304 B │ 419 B ║
-║ component │ 2.05 KB │ 1.57 KB ║
-║ controller │ 1.96 KB │ 1.45 KB ║
-║ debug │ 11.73 KB │ 8.14 KB ║
-║ deprecated-features │ 31 B │ 77 B ║
-║ destroyable │ 561 B │ 383 B ║
-║ enumerable │ 259 B │ 387 B ║
-║ helper │ 1.08 KB │ 830 B ║
-║ instrumentation │ 2.43 KB │ 1.78 KB ║
-║ modifier │ 1.22 KB │ 987 B ║
-║ object │ 35.98 KB │ 22.1 KB ║
-║ owner │ 159 B │ 178 B ║
-║ renderer │ 630 B │ 491 B ║
-║ routing │ 59.37 KB │ 33.91 KB ║
-║ runloop │ 2.36 KB │ 1.5 KB ║
-║ service │ 1 KB │ 858 B ║
-║ template │ 654 B │ 538 B ║
-║ template-compilation │ 429 B │ 366 B ║
-║ template-compiler │ 123.33 KB │ 59.68 KB ║
-║ template-factory │ 370 B │ 351 B ║
-║ test │ 923 B │ 627 B ║
-║ utils │ 4.11 KB │ 3.63 KB ║
-║ version │ 55 B │ 131 B ║
-╚══════════════════════╧═══════════╧══════════╝
+╔══════════════════════╤═══════════╤═══════════╗
+║ @ember/* │ Min │ Gzip ║
+╟──────────────────────┼───────────┼───────────╢
+║ Total │ 314.56 KB │ 182.99 KB ║
+╟──────────────────────┼───────────┼───────────╢
+║ -internals │ 36.64 KB │ 26.27 KB ║
+║ application │ 13.24 KB │ 8.11 KB ║
+║ array │ 13.05 KB │ 7.63 KB ║
+║ canary-features │ 304 B │ 419 B ║
+║ component │ 2.05 KB │ 1.56 KB ║
+║ controller │ 1.96 KB │ 1.4 KB ║
+║ debug │ 11.73 KB │ 8.12 KB ║
+║ deprecated-features │ 31 B │ 77 B ║
+║ destroyable │ 561 B │ 383 B ║
+║ enumerable │ 259 B │ 387 B ║
+║ helper │ 1.08 KB │ 797 B ║
+║ instrumentation │ 2.43 KB │ 1.78 KB ║
+║ modifier │ 1.22 KB │ 986 B ║
+║ object │ 36.7 KB │ 22.64 KB ║
+║ owner │ 159 B │ 178 B ║
+║ renderer │ 630 B │ 503 B ║
+║ routing │ 59.37 KB │ 34.29 KB ║
+║ runloop │ 2.36 KB │ 1.44 KB ║
+║ service │ 1 KB │ 829 B ║
+║ template │ 654 B │ 534 B ║
+║ template-compilation │ 429 B │ 366 B ║
+║ template-compiler │ 123.33 KB │ 59.68 KB ║
+║ template-factory │ 370 B │ 351 B ║
+║ test │ 923 B │ 627 B ║
+║ utils │ 4.11 KB │ 3.65 KB ║
+║ version │ 55 B │ 131 B ║
+╚══════════════════════╧═══════════╧═══════════╝
╔═════════════════╤══════════╤══════════╗
║ @glimmer/* │ Min │ Gzip ║
╟─────────────────┼──────────┼──────────╢
-║ Total │ 38.29 KB │ 21.76 KB ║
+║ Total │ 38.77 KB │ 22.04 KB ║
╟─────────────────┼──────────┼──────────╢
║ destroyable │ 2.78 KB │ 1.38 KB ║
║ encoder │ 81 B │ 171 B ║
@@ -53,7 +53,7 @@
║ program │ 252 B │ 333 B ║
║ reference │ 548 B │ 544 B ║
║ runtime │ 10.32 KB │ 5.22 KB ║
-║ tracking │ 1.34 KB │ 1.18 KB ║
+║ tracking │ 1.81 KB │ 1.46 KB ║
║ util │ 1.85 KB │ 1.59 KB ║
║ validator │ 15.53 KB │ 6.9 KB ║
║ vm │ 495 B │ 569 B ║Details
|
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
📊 Size reportTarball size — dist/dev 0.6%↑
dist/prod 0.6%↑
smoke-tests/v2-app-template/dist 0.9%↑
smoke-tests/v2-app-hello-world-template/dist 1%↑
🤖 This report was automatically generated by wyvox/pkg-size |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- Teach the glimmer-workspace `@test` decorator and suite runner to work under 2023-11 decorators (tag the function rather than relying on prototype enumerability). - Support stable decorators in `nativeDescDecorator`, which main now applies to getters on Component. - Add `onClassFinalized`, which queues per-class setup on the decorator metadata object and flushes it from `CoreObject.proto()` or on first construction. Use it for computed, action and nativeDescDecorator so they target the declaring class (not a subclass) and are visible to class-level introspection like `metaForProperty` before any instance exists. - Route `@service foo` fields through the same computed path as legacy decorators so injections are registered in the class meta. - Expose `VITE_` env vars again now that main sets `envPrefix`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Our public decorator types now include standard decorator signatures
alongside their legacy ones, so they type check with or without
`experimentalDecorators`:
- `tracked` (fields, accessors, and `@tracked({ ... })`), `cached`
- `computed` (bare and with keys), computed macros, `alias`
- `action`, `dependentKeyCompat`
- `service`/`inject` and controller `inject` (fields and accessors)
`readOnly()`/`oneWay()` now preserve the decorator's type so chained
decorators keep working under both modes.
Internally, decorated `declare` fields (which standard decorators
disallow) become regular fields, and new `type-check:*-stable-decorators`
scripts check both the internals and a new stable-decorators type-tests
suite with `experimentalDecorators: false`. CI runs both.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1f703f7 to
4440cfb
Compare
Add a third decorator variant for the test suite,
VITE_STABLE_DECORATORS=typescript, alongside babel's legacy decorators
(decorator-transforms) and babel's 2023-11 decorators. It compiles our
sources with `ts.transpileModule` (standard decorators, ES2022 target)
before babel runs, and drops babel's decorator plugins. CI runs it as a
new variant.
TypeScript's emit only provides decorator metadata when `Symbol.metadata`
already exists, which it doesn't in browsers yet, while babel falls back
to `Symbol.for('Symbol.metadata')`. `onClassFinalized` depends on that
metadata, so define `Symbol.metadata` with babel's fallback when it's
missing, and assert clearly if a class still ends up without metadata.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Rather than defining `Symbol.metadata` for every app, leave it to apps
that compile with TypeScript's decorator emit, as TypeScript's own docs
advise. Ember now looks the key up lazily (so it honors whatever the app
installed, falling back to babel's `Symbol.for('Symbol.metadata')`), and
the assertion for a class without metadata explains the polyfill. The
test suite's TypeScript mode adds the polyfill to the test page, the way
an app would.
Also add a smoke-test scenario that builds a v2 (vite) app with
TypeScript's emit: a vite plugin runs `ts.transpileModule` over the app's
own code before babel (and adds the polyfill), and babel's
decorator-transforms plugin is removed. It shares its app and test files
with the babel 2023-11 scenario, plus a TypeScript test covering field
`@tracked`/`@service`, `@cached` and `@action`.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
This is now essentially ready. It would be good to do some benchmarking. The tests run three ways:
The most practical option for apps who want to be early adopters is If you instead let TypeScript transpile your decorators, you need to follow TypeScript's instructions about adding your own Either way, it's expected that you'll get better performance if you update field decorators to auto accessor decorators (but field decorators continue to work). |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Here are the results with 50 samples each Also ignore how the table is in the bottom right corner of the window. This needs more CSS finesse 🙈 the p90 for this one bench very much favors accessors It's still pretty close. So, I think the benefits here are good enough! |
Four ember result sets for the stage 3 decorators PR: - main 74fb9ba2e8, legacy decorators (decorator-transforms) - PR 0ea35167d7, legacy decorators - PR, @babel/plugin-proposal-decorators 2023-11, `@tracked` fields - PR, same plugin, `@tracked accessor` Each file pools 5 mirrored rounds (50 samples per bench) at 8x throttle, all runs pinned to CPUs 4-7. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
huzzah! I fixed the table alignment in the bench viewer app 🙈 haha |
| if (elementDescriptor) { | ||
| return decorator(elementDescriptor[0], elementDescriptor[1], elementDescriptor[2]); | ||
| } else if (modernArgs) { | ||
| // TODO: cast is a lie, keeping the public types unchanged for now |
| ...args: any[] | ||
| ): TrackedDecorator | DecoratorPropertyDescriptor | TrackedValue<any> { | ||
| if (isModernDecoratorArgs(args)) { | ||
| // TODO: cast is a lie, keeping the public types unchanged for now |
| `You attempted to set a default value for ${decoratorArgs[1].name?.toString()} with the @tracked({ value: 'default' }) syntax. You can only use this syntax with classic classes. For native classes, you can use class initializers: @tracked field = 'default';`, | ||
| !hasInitialValue | ||
| ); | ||
| // TODO: cast is a lie, keeping the public types unchanged for now |
There was a problem hiding this comment.
lol controller inject
|
Taking notes from tooling team meeting discussion of this feature:
|
|
I am on the hook to write the aforementioned RFC & docs, but I'm going to land this PR now as it's green, reviewed, and safe. I don't want to keep rebasing it. |



Working on support for the stage3 decorator spec.
This branch is an attempt at complete drop-in support for all our decorators, even the wacky and wonderful old ones. I have the entire ember test suite passing locally.
My goal here is to show everything working with only the tiniest possible semantic changes and no mandatory syntactic change to auto-accessors.
You are still likely to want to convert to auto-accessors because they will perform much better. But keeping the old syntax working, even at a perf cost, would greatly ease upgrades.
Known semantic changes
TODO
trackedandservice. (I've already done this on prior attempts, it's the easier part. But I'll need to segregate them in their own test suite area, because I'm trying to keep everything working under both builds, and the old build won't support the syntax.)declare. We probably can't make ember's own build typecheck under both configurations, but we can probably offer enough overrides to demonstrate different apps working under both configurations.trackedget all the same computed property interop as the field form?addInitializerthe first time a class is instantiated. (Our field form oftrackeddoes a bunch of that, but the messiness there is more excusable since that's the allowed-to-be-slower legacy form.) This injects a little code into every object instantiation. Even in new apps that don't actually need it.