Repository navigation
Conversation
…tion A non-null assertion inside an optional chain (`a?.b()!.c`, `a?.b!()`) was lowered as a plain expression, so the inner `?.` was dropped from the output. Treat `TSNonNullExpression` as part of the chain, matching Babel's AST. Fixes oxc-project#28142
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e82b4a254
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Memoization can hide a required `TypeError` after an optional chain
short-circuits on an earlier render. For `obj?.a.b(getArg())`, rendering
first with `obj = undefined` caches `undefined`; rendering again with
`obj = {}` can reuse that result because the reduced dependency `obj?.a`
is still `undefined`. The second render should throw when reading `.b`.
Keep non-optional continuation dependencies below optional prefixes
instead of letting the prefix subsume them. When a computed or call
continuation cannot be represented as a property path, retain the
original optional guard dependency. For conditionally evaluated chains
such as `getArg() ? obj?.a.b(getArg()) : null`, truncate an unhoistable
dependency before its last optional link. This tracks the guard without
moving a throwing read ahead of its condition. Fully optional chains
keep their existing dependency reduction.
Adds 11 focused Node runtime cases comparing compiled and original
JavaScript over two consecutive renders, with truthy and falsy
conditions. They cover static, computed, optional-call, nested,
conditional, and fully optional chains, plus method receivers. Output
snapshots cover the generated dependencies.
This bug predates and is independent of
#28144. The same static,
computed, and optional-call failures were reproduced with
`babel-plugin-react-compiler@1.0.0` and `@babel/core@8.0.9`; this
intentionally corrects behavior also present upstream.
Validation:
- `cargo +1.99.1 test -p oxc_react_compiler --all-features`: 18 unit
tests, 26 integration tests, and the full snapshot suite passed.
- `cargo +1.99.1 clippy -p oxc_react_compiler --all-targets
--all-features -- -D warnings` passed.
- `cargo +1.99.1 fmt -p oxc_react_compiler -- --check` and `git diff
--check` passed.
- An additional local differential matrix of 73 expressions and 18,688
render transitions passed with no skipped compilations.
- NAPI binding tests were not run locally.
AI assistance: the implementation, regression tests, and PR description
were prepared with AI assistance.
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is now on by default (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. The README documents the bail-out and how to turn the check off, and qualifies its claim that the port compiles a superset of what the Babel plugin compiles. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is now on by default (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. The README documents the bail-out and how to turn the check off, and qualifies its claim that the port compiles a superset of what the Babel plugin compiles. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is now on by default (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. With panicThreshold set to 'critical_errors' or 'all_errors', the new diagnostic fails the build. The changeset and README document the bail-out, that build failure, reportDiagnostics to find the skipped components, and how to turn the check off. The README also notes that its production result still holds: the same functions in that app compile on 0.155.0 and 0.156.0. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is now on by default (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. With panicThreshold set to 'critical_errors' or 'all_errors', the new diagnostic fails the build. The changeset and README document the bail-out, that build failure, reportDiagnostics to find the skipped components, and how to turn the check off. The README also notes that its production result still holds: the same functions in that app compile on 0.155.0 and 0.156.0. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is now on by default (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. With panicThreshold set to 'critical_errors' or 'all_errors', the new diagnostic fails the build. The changeset and README document the bail-out, that build failure, reportDiagnostics to find the skipped components, and how to turn the check off. The README’s caveats section now says the port differs from the Babel plugin in both directions (compiling some code the Babel plugin bails on, skipping these functions it compiles), and dates the production results to the bindings they were measured on, 0.142.0, instead of claiming parity in the present tense. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is on by default again (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. It was on at 0.142.0, the plugin’s first pinned version, and off from 0.144.0 through 0.155.0. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. With panicThreshold set to 'critical_errors' or 'all_errors', the new diagnostic fails the build. The changeset and README document the bail-out, that build failure, reportDiagnostics to find the skipped components, and how to turn the check off. The README’s caveats section now says the port differs from the Babel plugin in both directions (compiling some code the Babel plugin bails on, skipping these functions it compiles), and dates the production results to the bindings they were measured on, 0.142.0, instead of claiming parity in the present tense. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exact pin in @acusti/vite-plugin-react-compiler, plus the root and docs devDependency ranges so bun hoists a single copy. Exhaustive manual memoization validation is on by default again (validateExhaustiveMemoizationDependencies, oxc-project/oxc#28101), as on React Compiler main: a component or hook whose useMemo or useCallback dependency list is missing a dependency or lists an extra one is skipped. It was on at 0.142.0, the plugin’s first pinned version, and off from 0.144.0 through 0.155.0. 0.155.0 and babel-plugin-react-compiler@1.0.0 compile it with the dependencies they infer, which changes when the value updates. The plugin keeps the upstream default. With panicThreshold set to 'critical_errors' or 'all_errors', the new diagnostic fails the build. The changeset and README document the bail-out, that build failure, reportDiagnostics to find the skipped components, and how to turn the check off. The README’s caveats section now says the port differs from the Babel plugin in both directions (compiling some code the Babel plugin bails on, skipping these functions it compiles), and dates the production results to the bindings they were measured on, 0.142.0, instead of claiming parity in the present tense. The release also fixes compiled output for: - an optional chain continued through a non-null assertion (`users?.find(…)!.name`), which lost its `?.` (oxc-project/oxc#28144) - a value that a branch inside `try` picks from props, or that `catch` assigns when a prop makes `try` throw, which was cached once per mount (oxc-project/oxc#27817, oxc-project/oxc#28005) - a `try` whose `catch` can never run, which panicked and aborted the process, or compiled the component to an empty function (oxc-project/oxc#28066) - optional-chain dependencies, which keep the reads after an optional link, so a cached value no longer hides a TypeError the uncompiled code throws (oxc-project/oxc#28165) - JSX outlining (opt-in `enableJsxOutlining`), which emitted invalid destructuring for hyphenated props like `aria-label` (oxc-project/oxc#28111) Every JS/TS file in the repo compiles to identical code and diagnostics on 0.155.0 and 0.156.0 (default and `compilationMode: 'all'`); the source maps of Dropdown.tsx and helpers.ts differ only in the `names` label of an optional-chain dependency. So do 9,706 TS/TSX/JSX files and a 4,000-file JS sample from this repo’s dependencies (compiled under a path outside node_modules), apart from five files in `compilationMode: 'all'` whose differences come from oxc-project/oxc#28165 and oxc-project/oxc#28005. No function changes whether it compiles, and the public typings differ only in the validateExhaustiveMemoizationDependencies default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled component printed `users?.find(…)!.name` as `users.find(…).name` through 0.155.0, which throws while `users` is undefined; kept as of 0.156.0 (oxc-project/oxc#28144), as babel-plugin-react-compiler@1.0.0 does. The test fails against 0.155.0 and passes against 0.156.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #28142
Before / After
Before:
users.find((user) => user.id === userId).name(the?.was dropped, so this throws whenusersis undefined)After:
users?.find((user) => user.id === userId).nameCause
In oxc the whole chain is one
ChainExpression, and the lowering decides whether a member or call is optional by walking its receiver spine (expr_contains_optional). ATSNonNullExpressionstopped that walk, and theotherarm in the optional member/call lowering then lowered it as a plain expression. Babel keeps the chain going through!, so the inner link should still be an optional member/call.Fix
expr_contains_optionallooks throughTSNonNullExpression.TSNonNullExpression, it is lowered withlower_chain_subexprso the inner link keeps its optional semantics.Tests
optional-chain-non-null-assertion.tsx(the issue repro) andoptional-chain-non-null-assertion-call.tsx(obj?.get!().valueandobj?.get?.()!.value), with snapshots.cargo test -p oxc_react_compilerpasses with no changes to existing snapshots;cargo clippy -p oxc_react_compiler --all-targets -- -D warningsandcargo fmtare clean.AI disclosure: this change was written with help from an AI assistant and reviewed and tested by me.