Skip to content

fix(aria): use Octane's useRef instead of the null-dropping cast - #2291

Merged
trueadm merged 1 commit into
mainfrom
fix/aria-useref-types
Oct 29, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/aria-useref-types

Conversation

@trueadm

@trueadm trueadm commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Delete the useRef cast in packages/aria/src/compat/react.ts. export * from 'octane' now supplies useRef, and the compat React default object takes it from Octane like every other hook.

Why

  • The cast existed because Octane rejected React 19's useRef<Element>(null). fix: type useRef<T>(null) and useRef<T>(undefined) like React 19 #2281 added React 19's useRef<T>(initial: T | null): { current: T | null } and (initial: T | undefined) overloads, so that is no longer true.
  • The cast was also wrong. Octane.useRef as <T>(initial: T | null) => { current: T } typed useRef<HTMLButtonElement>(null) as { current: HTMLButtonElement }. That drops the null that React's types and the upstream React Aria source rely on.

Changes

  • Removed the cast and its comment. Removed useRef from the Object.assign that builds the compat React object.
  • Runtime is unchanged: the cast wrapped the same Octane.useRef function. Compiled output for aria's call sites is unchanged too, because the compiler classifies a useRef imported from compat/react by that import, not by how compat/react defines it.
  • Types change only for the 11 bare useRef<X>(null) sites, whose current is now X | null. Six untyped useRef(null) sites now infer { current: null }, as React 19 does. The 25 useRef<X | null>(null) sites were already nullable.
  • No public signature changes. compat/react isn't in aria's exports map, none of index.ts, stately or components re-export it, and the only hook among the 11 changed sites (useAutoScroll) declares its return type. So there's no changeset.
  • packages/aria/audit/ pins no hash of compat/react.ts, so no audit update.

Validation

  • pnpm format:check (not run repo-wide; pnpm format:files:check packages/aria/src/compat/react.ts passes)
  • pnpm typecheck (not run repo-wide)
  • pnpm test (not run locally; left to CI)
  • pnpm exec octane-tsc -p packages/aria/tsconfig.json: 0 errors across 1,621 files with the cast removed. None of the ported React Aria source needed changes or ! assertions.
  • pnpm sync: no generated changes
  • perf-review: not applicable. Types-only change to a binding's compat module. No runtime, compiler, or hot-path code changes, and the runtime function is identical.
  • concise-code: src +1 −6 (runtime +0 −0); no new files or exports. Alternative considered: keep the wrapper and widen its return type to { current: T | null } (one line). Rejected because it would duplicate the overloads octane now declares. Bytes: not applicable.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Note

Low Risk
Types-only change to an internal compat module with identical runtime; consumers typechecking against pre-#2281 Octane may see new TS errors at bare useRef<X>(null) sites.

Overview
Removes the compat-layer useRef wrapper in packages/aria/src/compat/react.ts so useRef is re-exported from Octane via export * from 'octane', matching React 19's nullable ref typing after Octane #2281.

The deleted cast incorrectly typed useRef<X>(null) as { current: X } (dropping null); call sites now get { current: X | null } where that matters. The default React compat object no longer overrides useRef—only forwardRef is layered on. Runtime behavior is unchanged (same Octane.useRef function).

Reviewed by Cursor Bugbot for commit ba31102. Bugbot is set up for automated code reviews on this repo. Configure here.

octane now declares React 19's `useRef<T>(initial: T | null)` and
`useRef<T>(initial: T | undefined)` overloads (#2281), so the compat
layer no longer needs its own `useRef`. The cast it used typed
`useRef<Element>(null)` as `{ current: Element }`, dropping the `null`
that React and the upstream React Aria source rely on. `export * from
'octane'` now supplies `useRef`, with the same runtime function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 29, 2026 13:35
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 29, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp ba31102 Commit Preview URL

Branch Preview URL
Oct 29 2026, 01:37 PM

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) slower beyond ±3%

Compares 3430ec044, the merge commit's first parent with 640927b71 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

target operation base ms head ms head/base 95% CI
octane-jsx clear 45.992 45.117 +6.1% +3.3% … +10.3% 🟡 slower
All 20 timed operations (19 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 4.275 4.058 −4.8% −8.8% … +7.0% ⚪ within noise
octane-tsrx replace 8.283 7.392 −0.0% −10.2% … +2.4% ⚪ within noise
octane-tsrx add 3.283 3.017 −0.0% −17.6% … +2.6% ⚪ within noise
octane-tsrx update 0.099 0.103 −3.6% −30.6% … +3.7% ⚪ within noise
octane-tsrx select 0.009 0.010 +0.6% −9.7% … +20.4% ⚪ within noise
octane-tsrx swap 0.028 0.023 −6.5% −35.3% … +2.0% ⚪ within noise
octane-tsrx remove 0.016 0.016 +3.4% ±0.0% … +7.7% ⚪ within noise
octane-tsrx runlots 30.650 26.333 −1.6% −5.0% … +2.6% ⚪ within noise
octane-tsrx select_lots 0.008 0.007 −1.2% −4.5% … +2.8% ⚪ within noise
octane-tsrx clear 43.158 43.967 +0.0% −3.4% … +4.0% ⚪ within noise
octane-jsx run 3.692 3.525 ±0.0% −1.3% … +2.9% ⚪ within noise
octane-jsx replace 6.417 5.975 −1.6% −10.6% … +0.0% ⚪ within noise
octane-jsx add 3.242 3.017 +0.0% ±0.0% … +3.4% ⚪ within noise
octane-jsx update 0.189 0.191 +2.5% −3.5% … +8.9% ⚪ within noise
octane-jsx select 0.102 0.110 +0.7% −4.3% … +10.0% ⚪ within noise
octane-jsx swap 0.187 0.178 +0.5% −10.0% … +12.0% ⚪ within noise
octane-jsx remove 0.129 0.136 +0.9% −0.7% … +5.0% ⚪ within noise
octane-jsx runlots 29.542 30.000 −1.4% −5.3% … +1.7% ⚪ within noise
octane-jsx select_lots 0.998 1.154 +4.5% −3.3% … +17.7% ⚪ within noise
octane-jsx clear 45.992 45.117 +6.1% +3.3% … +10.3% 🟡 slower

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 111 measured values.

Public-import reachability bundles (bytes)

No changes across 141 measured values.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website ba31102 Commit Preview URL

Branch Preview URL
Oct 29 2026, 01:38 PM

@trueadm
trueadm merged commit 6c0ca86 into main Oct 29, 2026
55 checks passed
@trueadm
trueadm deleted the fix/aria-useref-types branch October 29, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant