Skip to content

fix(octane): type Strong host prop wrappers against Strong hosts - #2282

Merged
trueadm merged 1 commit into
mainfrom
fix/strong-host-prop-types
Oct 29, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/strong-host-prop-types

Conversation

@trueadm

@trueadm trueadm commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • In a "use strong" module, a shadcn-style wrapper that spreads ComponentProps<"span"> (or HTMLAttributes<T>, SVGProps<T>, …) onto its host now type-checks. Its callers must pass trustHTML(…) to the wrapper's dangerouslySetInnerHTML, as they would to the host.
  • The Strong TypeScript view reads octane through a new type-only octane/strong entry. That entry re-exports octane and narrows its React-shaped host prop types to the Strong host contract.

Why

Found while migrating Memos with @octanejs/codemod --strong (#2280): 12 UI wrappers (ui/badge, dialog, sheet, input, label, textarea, …) failed octane-tsc with TS2322. The compiler accepted each module and granted Strong mode, so only the typecheck failed. Nearly every shadcn or Base UI app has these wrappers, so without a fix a migrated UI kit cannot be Strong.

The error is correct as far as it goes. The compatibility ComponentProps<"span"> accepts a raw { __html } from callers, so a value of that type can never be assignable to a Strong host. The props type has to change; the Strong host contract cannot loosen. I weighed three options:

Option Outcome
Resolve ComponentProps and friends against the Strong host contract in Strong modules (this PR) Wrappers type-check with no source change. The TrustedHTML requirement moves to the wrapper's callers, in every module. No new names in octane's public API.
Export Strong-only props names for the codemod to emit Hand-written Strong wrappers would still hit an opaque TS2322. octane's public API is React names only.
Report it in the compiler so the module falls back to compatibility mode Most shadcn wrappers would leave Strong mode, which defeats the migration.

This extends what Strong already does: its type view selects the Strong JSX types automatically. ComponentProps<"span"> is React's name for "what <span> accepts", so in a Strong module it now means what a Strong <span> accepts.

Changes

  • packages/octane/src/strong.d.ts (new, types only, exported as octane/strong) re-exports octane and narrows each host prop type: ComponentProps, ComponentPropsWithRef, ComponentPropsWithoutRef, DOMAttributes, DetailedHTMLProps, HTMLProps, SVGProps, SVGAttributes, SVGLine/TextElementAttributes, every *HTMLAttributes, and JSX. In the narrowed types:

    • dangerouslySetInnerHTML requires TrustedHTML;
    • suppressHydrationWarning and suppressNativeChangeWarning are never.

    The narrowing is an intersection, so each Strong type stays assignable to its compatibility type, and a Strong wrapper can still spread its props onto a compatibility component such as a Base UI primitive. ComponentProps<typeof Component> keeps the component's authored props.

  • compileToVolarMappings: when the virtual TSX selects @jsxImportSource octane/strong, it rewrites import … from 'octane' to 'octane/strong', after every pass that recognises imports by their octane source. Runtime compilation and the inspection entry are unchanged.

  • package.json adds ./strong (source and publish); build.mjs copies the declaration into dist.

  • public-types.ts gains a one-line pointer to the Strong counterparts.

  • Docs: docs/strong-compiler-checks.md (Trusted HTML) and the website Strong mode guide.

  • Changeset: octane patch.

Validation

  • targeted tests: strong-html.test.ts extends the real-TypeScript Strong JSX harness with wrapper cases, all type-checked by a real ts.Program:
    • Strong wrappers over ComponentProps<"span">, ComponentPropsWithoutRef<'div'>, React.InputHTMLAttributes (namespace import, mixed with a value import), and React.SVGProps are clean;
    • callers: trustHTML passes, a raw { __html } fails naming TrustedHTML, and a spread suppressHydrationWarning fails;
    • a .ts helper importing from octane/strong works;
    • a compatibility wrapper still accepts raw HTML;
    • a Strong wrapper spreads onto a compatibility component.
  • Mutation checks. Each makes the test fail:
    • removing the import redirect: the original 4× TS2322;
    • making the narrowing a no-op;
    • using the JSX table's Omit+null shape: the spread onto the compatibility component fails.
  • vitest --project octane over the 12 Strong and Volar compiler files (strong-*, volar, native-reads, lazy-ref-strong, bundler-compiler): 2,364 passed.
  • octane-tsc -p packages/octane/tsconfig.json -p packages/octane/typetests/tsconfig.json -p packages/devtools/tsconfig.json -p packages/mdx/tsconfig.json -p website/tsconfig.json: clean. The website is compiler.strong: true (137 .tsrx modules), and --listFiles confirms its program loads strong.d.ts.
  • pnpm typecheck:coverage, pnpm format:files:check, pnpm sync (it only bumped the octane export count in docs/packages.md)
  • pnpm test, full pnpm typecheck, pnpm format:check: not run locally, per the local load rule; CI covers them.
  • perf-review: node scripts/perf-review-scan.mjs found no candidates. The change is type-only plus one editor-only AST pass, which runs once per Strong module in the type view. Runtime output, compiled output, and bundles are unchanged.
  • concise-code: src +126 −9 (runtime +0).
    • New file strong.d.ts: about 90 lines, one alias per React host prop type. It mirrors the existing list in public-types.ts and cannot be derived generically. One new subpath, octane/strong, whose caller is the type view.
    • Alternatives rejected:
      • narrowing only ComponentProps* (3 lines): HTMLAttributes/SVGProps wrappers hit the same TS2322;
      • a codemod-only import rewrite: it misses hand-written wrappers and needs value/type import splitting;
      • a fallback diagnostic: it keeps UI kits out of Strong mode.
    • Bytes: not applicable.

Risk / follow-ups

  • Codemod (packages/codemod): no change needed for .tsrx output; keep emitting import type { ComponentProps } from 'octane'. A .ts module that declares host props consumed by Strong wrappers (for example button-variants.ts with type ButtonProps = ComponentProps<'button'> & …) is not Strong-viewed and still resolves the compatibility types. Under --strong, the codemod could emit those type imports from octane/strong, keeping value imports on octane.
  • Migrated call sites: code that passes dangerouslySetInnerHTML={{ __html }} to a Strong wrapper now needs trustHTML(…). That is the intended guarantee, but it is newly visible.
  • Editor messages: in a Strong module, an error on an octane import (such as a misspelled export) names "octane/strong" in its message.
  • Not redirected: export … from 'octane' re-exports and import('octane') type queries in Strong modules keep the compatibility types.

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
Type-checking and editor-only AST rewriting only; no runtime or bundle output changes. Callers of Strong wrappers may newly need trustHTML for innerHTML props.

Overview
Fixes TS2322 on shadcn-style Strong wrappers that spread ComponentProps<'span'>, HTMLAttributes<T>, or similar onto a host while Strong JSX already requires TrustedHTML on the element.

Adds a type-only octane/strong entry that re-exports octane and narrows every React-shaped host prop alias: dangerouslySetInnerHTML must be TrustedHTML, and suppressHydrationWarning / suppressNativeChangeWarning are excluded. Host intrinsics still use ComponentProps<typeof MyComponent> for custom components, and the narrowed types stay assignable to compatibility props so a Strong wrapper can still spread onto a Base UI primitive.

When the Volar type view uses @jsxImportSource octane/strong, compileToVolarMappings rewrites import … from 'octane' to octane/strong so authored imports pick up the Strong host contract without changing runtime emit. Plain .ts helpers can import host prop types directly from octane/strong.

Docs, changeset, build/publish wiring, and strong-html.test.ts cover wrapper, caller, and compat-spread cases.

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

A Strong module's hosts take the Strong JSX types, but ComponentProps<"span">
and the other React-shaped host prop types it imported from octane still
described compatibility hosts, so a shadcn-style wrapper spreading its props
onto <span> failed octane-tsc with TS2322 on dangerouslySetInnerHTML.

The Strong TypeScript view now reads octane through a type-only octane/strong
entry that narrows those types to the Strong host contract: TrustedHTML for
dangerouslySetInnerHTML and no suppression props. The wrapper type-checks and
its callers supply the brand, so the TrustedHTML guarantee holds. The narrowed
types remain assignable to the compatibility ones.

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:37
@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 4d2945e Commit Preview URL

Branch Preview URL
Oct 29 2026, 10:39 AM

@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 4d2945e Commit Preview URL

Branch Preview URL
Oct 29 2026, 10:39 AM

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark report

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

Compares 29d1117db, the merge commit's first parent with d0d164e0b 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 4.900 4.008 −5.5% −19.4% … +0.6% ⚪ within noise
octane-tsrx replace 6.375 7.008 −0.8% −5.0% … +4.4% ⚪ within noise
octane-tsrx add 2.567 2.575 ±0.0% −4.0% … +0.0% ⚪ within noise
octane-tsrx update 0.114 0.123 −0.3% −11.7% … +22.3% ⚪ within noise
octane-tsrx select 0.007 0.009 −0.6% −4.7% … +2.3% ⚪ within noise
octane-tsrx swap 0.019 0.024 −0.3% −5.2% … +11.1% ⚪ within noise
octane-tsrx remove 0.017 0.018 +0.4% −4.4% … +2.5% ⚪ within noise
octane-tsrx runlots 29.308 24.908 −3.8% −6.6% … +1.4% ⚪ within noise
octane-tsrx select_lots 0.008 0.008 −0.9% −6.6% … +3.4% ⚪ within noise
octane-tsrx clear 40.725 43.100 +7.5% +2.6% … +11.7% ⚪ within noise
octane-jsx run 4.242 3.708 ±0.0% −5.2% … +2.6% ⚪ within noise
octane-jsx replace 7.050 6.467 −0.7% −4.3% … +4.7% ⚪ within noise
octane-jsx add 3.617 3.450 +1.6% −3.2% … +6.5% ⚪ within noise
octane-jsx update 0.186 0.200 +9.6% +2.5% … +13.0% ⚪ within noise
octane-jsx select 0.091 0.093 +0.5% −3.9% … +3.3% ⚪ within noise
octane-jsx swap 0.134 0.147 +4.6% +2.7% … +8.6% ⚪ within noise
octane-jsx remove 0.136 0.137 +3.1% −2.1% … +13.3% ⚪ within noise
octane-jsx runlots 30.367 34.850 +1.0% −5.9% … +8.7% ⚪ within noise
octane-jsx select_lots 1.006 0.983 +0.0% −8.1% … +2.7% ⚪ within noise
octane-jsx clear 45.408 42.667 −1.4% −9.8% … +2.9% ⚪ 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.

@trueadm
trueadm merged commit 3f3bf1a into main Oct 29, 2026
55 checks passed
@trueadm
trueadm deleted the fix/strong-host-prop-types branch October 29, 2026 10: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