Skip to content

fix(codemod): fix what migrating Memos and T3 Code found - #2280

Merged
trueadm merged 11 commits into
mainfrom
fix/codemod-t3code
Oct 29, 2026
Merged

trueadm merged 11 commits into
mainfrom
fix/codemod-t3code

Conversation

@trueadm

@trueadm trueadm commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes from migrating two popular open-source React apps with @octanejs/codemod --strong:
Memos (React 19, Vite, React Router, TanStack Query, Base UI; 458 modules) and
T3 Code (React 19, Vite, TanStack Router, Base UI, Tiptap, Effect; 968 modules).
I type-checked the output with octane-tsc against this branch's packages. t3.chat itself is closed source, so T3 Code is the T3 team's open-source app.

Every fix has a test that fails without it. A new app-shapes golden fixture collects the real shapes the two apps hit, and its output is compiled as part of the test.

Memos T3 Code
Codemod errors before → after 85 → 61 251 → 248
octane-tsc errors before → after 262 → 68 not run (six unported libraries)
Strong 259 / 345 509 / 727
Ran in the browser yes: against its Go backend, beside the React original no (bindings missing)

The remaining codemod errors are missing bindings (react-hot-toast, @effect/atom-react, @legendapp/list, @clerk/react, ...), createRef in tests, and one class error boundary per app.

Changes

  • Text-field wrappers (native-text-change). A shadcn-style Input/Textarea that spreads its rest props onto the field passed React's per-keystroke onChange through as Octane's native change, which fires on blur, so every controlled field in Memos stopped updating as you type. The codemod now destructures onChange out of the rest and passes onInput={onChange} before the spread, so a caller's own onInput still wins. It only does this when every other read of the rest is a member other than onChange. Anything else (<input {...props}> with whole props, or a rest also spread elsewhere) is reported.

  • React's global namespace (imports). React.ReactNode, React.FC, React.ChangeEvent written with no import (29 Memos and 31 T3 Code modules) now map to Octane's types.

  • forwardRef type arguments were copied as text, so React.ComponentPropsWithoutRef<"div"> survived in every shadcn component. They are now emitted through the rewriter.

  • e.target → e.currentTarget (event-object). This now also applies:

    • in a handler a component passes on to a control, read from the project's types (<Input onChange={(e) => …}>), including React 19.2's two-argument ChangeEvent<C, T>;
    • in handlers annotated with a union of controls;
    • in onFocus/onBlur.
  • Declaration files were skipped entirely. declare module "react" { namespace JSX { … } } custom-element typing now targets octane/jsx-runtime, and other augmentations of React's own types are reported. .d.ts files are never compiled. A file whose only import was import 'react' keeps export {};, so its declare module still augments rather than replaces.

  • Binding detection. A package was flagged as needing a binding:

    • by its name, when its export map hid package.json (@vitejs/plugin-react);
    • by a React peer that only its ./react entry uses (@usememos/editor, @pierre/trees, @clerk/electron).

    The codemod now reads the manifest through readInstalled, newly exported from @octanejs/cli, which walks node_modules by hand.

  • Children read as elements (descriptor-children, found by running Memos). A component that hands its children to Base UI's render prop crashed the memo list when the first memo was saved: React passes JSX children as elements, Octane as a compiled render body. Components whose own children reach render={…}, cloneElement, Children.* or isValidElement are now wrapped in descriptorChildren, so callers pass elements. Their call sites in the module keep conditional children as expressions, because an @if there handed Base UI a fragment and the tooltip never opened. A function declaration becomes a marked const unless module-load code reads it first, in which case it is reported.

  • Added imports use the module's own quote style.

  • docs/octane-codemod-plan.md gains a "Memos and T3 Code" section. The README rules table lists the new rewrites.

Validation

  • targeted tests: pnpm vitest run --project codemod, 60/60. Each new test was checked to fail with its fix reverted.
  • octane-tsc -p packages/codemod/tsconfig.typecheck.json and -p packages/cli/tsconfig.typecheck.json
  • pnpm format:files:check, and pnpm sync (no generated changes)
  • Memos and T3 Code migrated with this branch, Memos type-checked as above
  • pnpm test, pnpm typecheck, pnpm format:check (repo-wide; not run, per the local test load rule; CI covers them)
  • Memos ran in the browser with your approval. Setup: its Go server on SQLite on localhost, the migrated web app on Vite with @octanejs/vite-plugin, and the original React app beside it on the same server for comparison.
    • Four local stand-ins (not in this PR): a toast store for react-hot-toast; @usememos/editor/react migrated by the codemod itself; a react-leaflet placeholder; the class error boundary hand-ported to @try/@catch.
    • Worked with no console errors: sign-up, the timeline, creating, editing and pinning memos, tags, search, the memo page with comments, all 17 settings sections, the SSO form dialog, and 11 more routes.
    • Controlled Input fields kept each keystroke while focused.
    • The descriptor-children fix above was verified there: memos save, and the timestamp tooltip opens with Base UI's trigger props on the link.
    • Raw **bold** in memo bodies renders identically in the React original.
  • perf-review: not applicable. Developer tooling only; no runtime, compiler output, or binding hot path.
  • concise-code: src +236 −55, all in packages/codemod/src except the one-line readInstalled export (and its declaration) in @octanejs/cli, which reuses the CLI's existing manifest walk instead of a second one. attributeOf replaces four copies of a find-attribute-by-name lambda, and projectType is shared by typeOf and the event check.
    • New files: the app-shapes fixture pair and a changeset. New export: readInstalled, whose caller is the codemod.
    • Alternatives rejected:
      • Recording each binding's subpaths in the CLI catalog, to settle the "Check that @octanejs/base-ui/dialog exists" warnings: about +110 kB on a 243 kB file.
      • Only warning on text-field wrappers (about 15 lines): every migrated shadcn form would still break.
    • Bytes: not applicable.

Risk / follow-ups

Owned elsewhere, found by this run and not fixed here:

  • Compiler: .tsrx keeps type-only import names (blocks running any migrated app). TypeScript drops an import of a name used only as a type; the Octane compiler keeps it, so 30 Memos modules fail to link (does not provide an export named 'InstanceProfile') and the app is a blank page. I marked them type by hand to keep going. This is the existing proposed session ".tsrx keeps imports of type-only names".
  • Compiler, .tsrx TypeScript view (compileToVolarMappings), fixed by fix(compiler): typecheck generic arrows and directive arm exits in the .tsrx type view #2284 and merged into this branch:
    • It prints <T,>(…) => as <T>, which TypeScript reads as JSX.
    • It reports TSRX2005 for return null in an @for row, which the compiler and the authoring rules allow.
    • Both reproduce in a five-line .tsrx file.
  • Types:
  • Bindings: Base UI's evaluateRenderProp calls a compiled children body as a render function (an opaque parentNode crash) instead of guarding with isChildrenBlock like its other render-prop sites.
  • Codemod, later: a descriptorChildren component used from another module still gets @if children at those call sites.
  • Bindings (types):
    • @octanejs/remix-router lacks LinkProps and types Link's ref more narrowly than React Router.
    • The libraries listed above have no binding.

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

Medium Risk
Migration rewrites affect form event wiring, children semantics, and type augmentations—easy to miss edge cases despite broad tests, but scope is codemod/CLI tooling rather than production runtime paths.

Overview
Hardens @octanejs/codemod using defects found migrating Memos and T3 Code, with golden app-shapes coverage and expanded tests.

Controlled inputs and events: shadcn-style Input/Textarea wrappers that spread rest props now pull onChange out and wire onInput={onChange} before the spread so Octane does not treat React’s per-keystroke handler as native commit-time change. Unsafe spreads are warned instead of silently breaking forms. e.target rewrites to e.currentTarget also apply when project types say the handler is forwarded from a wrapper control, for union-typed controls, and on onFocus/onBlur.

Types and imports: unimported React.* global namespace types map to Octane equivalents; forwardRef generic arguments are emitted through the type rewriter (not left as raw React. text). .d.ts files are migrated: JSX intrinsic augmentations move from declare module 'react' to octane/jsx-runtime, other React augmentations are reported, and script-style declaration files get export {} so augmentations still merge.

Children and bindings: components that treat children as elements (render={children}, cloneElement, Children.*, isValidElement) are wrapped with descriptorChildren, and their in-module call sites keep conditional children as expressions (not @if fragments). Missing-binding detection reads installed package.json via newly exported readInstalled from @octanejs/cli, so export-map-hidden packages and ./react-only peers are not mis-flagged. New imports match the file’s quote style.

Docs/changeset record corpus numbers and remaining follow-ups outside this PR.

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

Migrating two popular open-source React apps (Memos, T3 Code) and
type-checking the output with octane-tsc turned up these codemod gaps:

- shadcn-style Input/Textarea wrappers spread rest props onto the field,
  so React's per-edit onChange became Octane's commit-time change; take it
  out of the rest and pass it as onInput before the spread
- React's global namespace types (React.ReactNode with no import) and
  forwardRef type arguments kept their React types
- e.target in a handler a component passes on to a control, typed by the
  project (React 19.2's ChangeEvent<C, T> included), and in onFocus/onBlur
- .d.ts files were skipped; JSX custom-element augmentations now target
  octane/jsx-runtime
- packages were reported as needing a binding by name when their export
  map hid package.json, or by a React peer only their ./react entry uses
- added imports follow the module's quote style

Memos: 85 -> 61 codemod errors (all bindings, createRef, one class),
262 -> 68 octane-tsc errors. T3 Code: 251 -> 248 codemod errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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
@trueadm
trueadm marked this pull request as ready for review October 29, 2026 10:17
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 29, 2026 •

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 7ff56c4 Commit Preview URL

Branch Preview URL
Oct 29 2026, 12:01 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 29, 2026 •

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 7ff56c4 Commit Preview URL

Branch Preview URL
Oct 29 2026, 12:00 PM

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares 23a25c295, the merge commit's first parent with 4c00a216a 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

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.167 2.858 +0.0% −3.6% … +4.6% ⚪ within noise
octane-tsrx replace 5.917 5.900 −4.9% −7.7% … +2.5% ⚪ within noise
octane-tsrx add 2.258 2.250 +0.0% −4.3% … +4.6% ⚪ within noise
octane-tsrx update 0.089 0.087 −1.0% −3.6% … +1.3% ⚪ within noise
octane-tsrx select 0.006 0.006 +2.2% −1.2% … +5.2% ⚪ within noise
octane-tsrx swap 0.017 0.016 −0.6% −4.9% … +3.2% ⚪ within noise
octane-tsrx remove 0.015 0.014 +1.7% −7.5% … +7.0% ⚪ within noise
octane-tsrx runlots 24.158 23.708 −1.6% −6.3% … +2.0% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −0.6% −2.3% … +3.6% ⚪ within noise
octane-tsrx clear 49.408 49.175 +2.9% −2.5% … +5.9% ⚪ within noise
octane-jsx run 4.050 3.767 +2.8% −2.7% … +8.6% ⚪ within noise
octane-jsx replace 7.500 7.533 +3.9% −6.5% … +22.6% ⚪ within noise
octane-jsx add 3.375 3.400 −3.2% −8.2% … +1.7% ⚪ within noise
octane-jsx update 0.170 0.165 +1.4% −2.1% … +3.2% ⚪ within noise
octane-jsx select 0.083 0.079 −0.8% −3.6% … +0.5% ⚪ within noise
octane-jsx swap 0.125 0.126 −0.3% −2.0% … +0.7% ⚪ within noise
octane-jsx remove 0.111 0.109 −0.0% −1.2% … +3.7% ⚪ within noise
octane-jsx runlots 27.842 28.592 −0.4% −4.5% … +4.5% ⚪ within noise
octane-jsx select_lots 0.897 0.960 +6.9% +0.3% … +11.4% ⚪ within noise
octane-jsx clear 50.433 53.575 +4.5% +1.0% … +8.3% ⚪ within noise

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Augmentation files lose module imports
    • Side-effect imports (no importClause) of React modules are now rewritten in place with replaceSpecifier instead of being deferred to finishImports, which was silently dropping them because it skips clause-less imports.

Create PR

Or push these changes by commenting:

@cursor push 9435062c8e
Preview (9435062c8e)
diff --git a/packages/codemod/src/transform.js b/packages/codemod/src/transform.js
--- a/packages/codemod/src/transform.js
+++ b/packages/codemod/src/transform.js
@@ -1117,6 +1117,10 @@
 			);
 		}
 		if (module in REACT_MODULES) {
+			if (!node.importClause) {
+				this.count(RULE.import);
+				return this.replaceSpecifier(node, node.moduleSpecifier, REACT_MODULES[module]);
+			}
 			this.importSlots.push(node);
 			return `\u0000IMPORT${this.importSlots.length - 1}\u0000`;
 		}

diff --git a/packages/codemod/tests/project.test.js b/packages/codemod/tests/project.test.js
--- a/packages/codemod/tests/project.test.js
+++ b/packages/codemod/tests/project.test.js
@@ -183,6 +183,7 @@
 			"import type { HTMLAttributes } from 'octane';\ndeclare module 'octane/jsx-runtime' {\n\tnamespace JSX {\n\t\tinterface IntrinsicElements { 'x-clock': HTMLAttributes<HTMLElement> }\n\t}\n}\n",
 		);
 		const css = result.files.find((f) => f.file === 'src/css.d.ts');
+		expect(code('src/css.d.ts')).toContain("import 'octane'");
 		expect(css?.notes.map((note) => note.rule)).toEqual(['unsupported-api']);
 		expect(css?.diagnostics).toEqual([]);
 		expect(code('src/Chart.tsx')).toContain("from '@octanejs/visx/hierarchy'");

You can send follow-ups to the cloud agent here.

Comment thread packages/codemod/src/transform.js Resolved
Running the migrated Memos app against its own backend crashed the memo
list as soon as a memo was saved: a component passed its `children` to
Base UI's `render` prop, which clones an element, but Octane passes JSX
children as a compiled render body.

Components whose own `children` reach `render={…}`, `cloneElement`,
`Children.*` or `isValidElement` are now wrapped in `descriptorChildren`,
so callers pass element descriptors as React does. A function declaration
becomes a marked `const` unless module-load code reads it first, in which
case it is reported. Call sites in the module keep their conditional
children as expressions: an `@if` there handed Base UI a fragment, so the
trigger props never reached the link and the tooltip never opened.

Also records the Memos runtime results in the plan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm and others added 2 commits October 29, 2026 10:46
A declaration file whose only import is `import 'react'` imports it so its
`declare module` augments the module. Dropping that import made the file a
script, where `declare module` declares the module instead: a JSX
custom-element file then replaced octane/jsx-runtime's types (even `<div>`
stopped typechecking), and a CSSProperties file would redefine `react`. When
the React imports leave nothing behind and nothing else makes the file a
module, `export {};` takes their place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/codemod/src/transform.js Resolved
Comment thread packages/codemod/src/transform.js Resolved
trueadm and others added 2 commits October 29, 2026 11:06
Review follow-ups for the descriptor-children rule:

- A function with overload signatures stays as it is and is reported:
  turning its implementation into a `const` left the signatures behind as
  `function` declarations.
- The hoisting check walked only direct reads. It now follows what runs
  while the module loads before the declaration: a callback or IIFE that
  code runs, and any call of a binding the module declares, which might
  reach the component. A function that is only defined runs nothing.
- Only module-level components are marked, since the compiler reads the
  marker from module-level `const` bindings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/codemod/src/transform.js Resolved
Comment thread packages/codemod/src/transform.js Resolved
trueadm and others added 2 commits October 29, 2026 11:20
…rtions

- A declaration file with no import or export is a script, where `declare
  module` declares the module instead of adding to it. When the codemod
  retargets such a file's JSX augmentation to octane/jsx-runtime, it now adds
  `export {};`, as it already did when dropping a React import; otherwise the
  file replaced Octane's JSX types. A React augmentation it only reports is
  left as written.
- `render={children as ReactElement}`, `cloneElement(children!)` and
  `satisfies` around `children` now mark the component too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hoist check skips nested runners
    • The runs check now walks up through ParenthesizedExpression, PropertyAssignment, ObjectLiteralExpression, ArrayLiteralExpression, and SpreadElement before testing whether the ancestor is a CallExpression/NewExpression, so parenthesized IIFEs and methods/arrows inside object arguments are correctly recognized as running at load time.

Create PR

Or push these changes by commenting:

@cursor push 625694007b
Preview (625694007b)
diff --git a/packages/codemod/src/transform.js b/packages/codemod/src/transform.js
--- a/packages/codemod/src/transform.js
+++ b/packages/codemod/src/transform.js
@@ -863,10 +863,20 @@
 		const visit = (/** @type {ts.Node} */ node) => {
 			if (!safe) return;
 			if (isFunctionLike(node)) {
-				const call = node.parent;
+				let wrapped = /** @type {ts.Node} */ (node);
+				while (
+					ts.isParenthesizedExpression(wrapped.parent) ||
+					ts.isPropertyAssignment(wrapped.parent) ||
+					ts.isObjectLiteralExpression(wrapped.parent) ||
+					ts.isArrayLiteralExpression(wrapped.parent) ||
+					ts.isSpreadElement(wrapped.parent)
+				) {
+					wrapped = wrapped.parent;
+				}
+				const call = wrapped.parent;
 				const runs =
 					(ts.isCallExpression(call) || ts.isNewExpression(call)) &&
-					(call.expression === node || call.arguments?.includes(/** @type {any} */ (node)));
+					(call.expression === wrapped || call.arguments?.includes(/** @type {any} */ (wrapped)));
 				if (!runs) return;
 			} else if (ts.isIdentifier(node) && node !== fn.name) {
 				const declaration = this.declarationOf(node);

You can send follow-ups to the cloud agent here.

Comment thread packages/codemod/src/transform.js Resolved
trueadm and others added 2 commits October 29, 2026 11:40
The descriptor-children hoisting check walked a nested function only when it
was a direct callee or argument, so a parenthesized IIFE, or a method on an
object handed to an imported call, slipped through. It now assumes every
function in load-time code runs, except one that is only defined there (a
declaration, or a variable's value through `memo` or `forwardRef`), and
treats handing a local binding to a call like calling it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blacksmith-sh

This comment has been minimized.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Optional React peer skips binding detection
    • Removed the standalone peerDependenciesMeta?.react?.optional disjunct from the early-return condition so that only an actual ./react export triggers the skip, allowing packages with optional React peers on their root entry to be correctly flagged as missing bindings.

Create PR

Or push these changes by commenting:

@cursor push 4f588c4a2d
Preview (4f588c4a2d)
diff --git a/packages/codemod/src/project.js b/packages/codemod/src/project.js
--- a/packages/codemod/src/project.js
+++ b/packages/codemod/src/project.js
@@ -443,9 +443,8 @@
 /**
  * Whether a package renders through React: it declares `react` as a peer or
  * dependency when installed, or its name says so when it is not. A package
- * with a `./react` entry (`@pierre/trees/react`), or an optional React peer
- * for one, renders through React there, which the caller matches by subpath;
- * its other entries need no binding.
+ * with a `./react` entry (`@pierre/trees/react`) renders through React there,
+ * which the caller matches by subpath; its other entries need no binding.
  *
  * @param {string} name
  * @param {string} from
@@ -454,7 +453,7 @@
 	if (name === 'octane' || name.startsWith('@octanejs/') || name.startsWith('node:')) return false;
 	const manifest = readInstalled(path.dirname(from), name)?.manifest;
 	if (!manifest) return REACT_PACKAGE.test(name);
-	if (manifest.exports?.['./react'] || manifest.peerDependenciesMeta?.react?.optional) return false;
+	if (manifest.exports?.['./react']) return false;
 	return ['peerDependencies', 'dependencies'].some((field) => manifest[field]?.react !== undefined);
 }

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit e9d6c1c. Configure here.

Comment thread packages/codemod/src/project.js Resolved
…ional peer

An optional React peer does not say which entries use React: a package can
use it in its root entry when React is installed. Only a dedicated `./react`
export now marks the other entries as React-free; a package with an optional
peer and no such entry is reported as needing a binding again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 3430ec0 into main Oct 29, 2026
33 checks passed
@trueadm
trueadm deleted the fix/codemod-t3code branch October 29, 2026 13:01
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