Skip to content

Bi-directional React bridge: React packages on Octane out of the box, and Octane inside React - #110

Closed
WebEferen wants to merge 8 commits into
mainfrom
react-compat-poc
Closed

WebEferen wants to merge 8 commits into
mainfrom
react-compat-poc

Conversation

@WebEferen

@WebEferen WebEferen commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

What this is

Octane's React adoption story, in both directions, with runnable proof — rebased onto current main (the parity fixes, SSR API, and MCP rework from the original branch already landed via the React-parity waves; this PR brings only what main lacks: the bridge itself).

Direction Package One-line setup
React packages on Octane @octanejs/react-compat octane({ compat: [react()] })
Octane components inside React @octanejs/react-wrapper wrapOctane(Component)

The goal is adoption from both sides: an Octane app gets the React ecosystem out of the box (99%-compatibility target — no codemods, no ports), and a React app can adopt Octane one component at a time.

Direction 1 — unmodified React packages run on Octane

// vite.config.js — this is the complete setup
import { octane } from 'octane/compiler/vite';
import { react } from '@octanejs/react-compat/vite';

export default { plugins: [octane({ compat: [react()] })] };

Package code keeps importing react, react/jsx-runtime, react-dom; the plugin resolves those to Octane facades (separate server facades under SSR). Hooks dispatch by call order into Octane slots, class components (state, commit lifecycles, contextType, Error Boundaries) are adapted, text-input onChange and SyntheticEvent semantics are translated, thrown-Promise Suspense and lazy route to Octane boundaries — and ReactDOMServer.renderToString/renderToStaticMarkup now delegate to octane/server's React-parity renderers.

Verified against the real npm builds (not ports): react-redux, jotai, react-hook-form, react-error-boundary, tailwindcss v4 — plus a 670-line edge-case contract suite (Error Boundaries, classes, refs, portals, SSR/hydration, identity, events). What does not run fails with targeted errors instead of silently approximating React (legacy class lifecycles, streaming react-dom/server, RSC, StrictMode double-invoke).

At a .tsrx JSX site, a React-package component crosses the boundary through resolveCompatType(Component).

Direction 2 — Octane components inside a React app

import { wrapOctane, OctaneWrapper } from '@octanejs/react-wrapper';

const Counter = wrapOctane(OctaneCounter);   // a first-class React component
<Counter step={5} />;

<OctaneWrapper component={Panel} props={{ title: 'Settings' }}>
  <ReactSettingsForm />                      {/* React children inside Octane DOM */}
</OctaneWrapper>;

Real react/react-dom stay the host (peer deps). The wrapper mounts an Octane root into a container element and keeps the renderers glued:

  • Props re-render through the Octane root's same-body fast path on every React commit — Octane state, effects and DOM survive React re-renders.
  • Timing: Octane renders flush synchronously (Octane flushSync) from a layout effect, before the browser paints the React commit.
  • Children bridge: the Octane component receives children as a layout-neutral display: contents host slot; the wrapper portals the React children into it. The slot descriptor is minted once per instance — stable element identity is what keeps Octane's reconciler out of the React-owned portal content.
  • React → Octane → React → Octane nesting composes; unmount runs Octane effect cleanups; StrictMode's double mount/unmount is handled.

Internals split by responsibility: useOctaneRoot (root lifecycle), useChildSlot (children bridge + the identity invariant), index.ts (public surface).

Runtime & compiler support (small, opt-in)

  • A WeakMap-keyed compat hook cursor (beginCompatHookRender / nextCompatHookSlot / finishCompatHookRender) with Rules-of-Hooks validation — zero fields added to native scopes.
  • Thrown-Promise Suspense normalization at every boundary catch site (React ecosystem code may throw a Promise directly instead of calling use()).
  • A React-parity same-element-reference bailout on the descriptor reconcile path: rendering the identical element object skips its subtree — which is also what protects bridged portal content.
  • octane({ tsx: false }) (bundler core + Vite adapter): React owns .tsx, Octane compiles only .tsrx — the mixed-renderer setup both example apps build on.

Runnable demos (both verified in Chromium)

playground/octane-in-react — a plain React app (StrictMode, @vitejs/plugin-react) hosting compiled .tsrx: a React slider drives an Octane counter's step while its Octane useState survives, a React form lives inside an Octane card, a toggled Octane clock proves effect cleanup.

playground/react-in-octane — an Octane app with no React installed: two React islands share one jotai atom (the real package's store wiring keeps them in sync) and a react-hook-form signup form runs with validation, watch() and submit — islands authored as plain React .tsx.

pnpm --filter octane-in-react-example dev
pnpm --filter react-in-octane-example dev

A Playwright smoke run drives 13 cross-renderer interactions across both apps (props flow, state survival, shared package state, form semantics, teardown) — all passing.

Tooling repositioned around the new story

  • The MCP octane_bridge_react_package tool now reports runtime-compat verdicts (works-out-of-the-box / works-with-caveats / has-unsupported-apis), scans for legacy class lifecycles, and its plan leads with the compat one-liner; native @octanejs/* ports become the optional performance path (via the octane export condition).
  • Skills, READMEs, rulesync rules, and the generated package inventory present the two packages as one bi-directional bridge.

Validation

  • Bridge suites: 71 tests green (react-compat-native, react-compat-ssr, react-wrapper, plus the MCP verdict tests) against main's runtime
  • Full monorepo suite matches main's baseline on the same machine (the only failures — base-ui differential timeouts, lucide dynamic-icon, three browser bundlers — reproduce identically on pristine origin/main)
  • pnpm typecheck (including the two new packages), pnpm format:check, changeset check, package inventory, and examples catalog: all clean
  • Both demos vite build cleanly and pass the browser smoke run

WebEferen added 8 commits July 3, 2026 21:56
Runtime (React parity):
- useReducer dispatch no longer eagerly bails on Object.is-equal state; a
  no-op action renders the component once, per
  ReactHooksWithNoopRenderer-test.js:3889.
- Unguarded render-phase setState now throws "Too many re-renders" after 25
  same-block re-renders in one drain (catchable by @try/ErrorBoundary)
  instead of hanging the flush.

Conformance tests:
- conformance/derived-state.test.ts: guarded render-phase updates (derived
  state from props, multi-step convergence), the new re-render cap, initial
  value is mount-only, same-value sets skip renders and effects,
  bail-then-change, updater queues observe pending state, set-then-revert,
  cleanup/setup closure freshness.
- conformance/eager-bailout.test.ts: ReactHooks-test.internal.js edges:
  same-state sets skip child renders/effects/commit and bail repeatedly,
  context change defeats the bailout, no-op reducer actions apply in order
  within a batch. React's extra post-update render (double-buffering
  artifact) is documented as a benign divergence.
- tests/_helpers.ts: a throwing initial mount detaches its container so
  leaked duplicate ids cannot break later #id selector queries.

SSR:
- renderToString(component, props?, options?) is the public entry (render
  kept as deprecated alias) with RenderOptions: signal (AbortSignal), nonce
  (CSP nonce on inline style/seed tags), timeoutMs (per-render suspense
  deadline). Covered in ssr-render-api.test.ts.
- Fixed stale "head is empty" docstrings, marked the ssr* exports as the
  compiler's private ABI, fixed the vite plugin dev RPC handler referencing
  a nonexistent executeServerFunction export, new docs/ssr.md with the
  missing-features roadmap (streaming, selective hydration, production
  build).

MCP server (0.2.0):
- Skills now ship inside the npm package (bridge-react-package,
  migrate-react-component, react-divergences, setup-ssr) so the server
  works outside the monorepo checkout.
- New octane_bridge_react_package tool: scans a React package or source dir
  for React API usage and returns an Octane compatibility report (verdict,
  vanilla-core detection, existing @octanejs binding, step-by-step plan);
  octane_bindings lists the official ports.
- Maintainer tools (project map, triage, validate plan, benchmarks, issue
  context) register only when an octane monorepo checkout is detected.
- Staleness fixes: radix binding in path triage, project map, skills, and
  the root README package list.
The interim executeServerFunction used JSON, but the RPC stack is built on
@ripple-ts/adapter, whose client stub encodes the argument array with
devalue and reads the response as a devalue-encoded { value } envelope.
The formats are silently incompatible (devalue's indexed-graph output is
itself valid JSON, so JSON.parse would produce wrong arguments instead of
throwing). Mirror ripple's server implementation with devalue so rich
values (Dates, Maps, undefined, cycles) round-trip and the future compiler
client stub stays compatible.
Revert the renderToString rename from earlier in this branch: render(
component, props?, options?) stays the single public name, per review
decision. The RenderOptions additions (signal, nonce, timeoutMs) and the
docs/ssr.md guide are unchanged apart from the name; the deprecated alias
and its tests are dropped, and the hacker-news examples return to their
original local `render as renderToString` import.
The vite plugin's original ssrLoadModule('octane/server') wiring was the
intended architecture (mirroring ripple/server, which exports the executor
from the framework so it runs inside the SSR module graph); the bug was
only the missing export on the octane side. Restore the plugin's original
line, implement executeServerFunction in octane/server with the devalue
wire format ripple's client stub defines, move the devalue dependency from
the plugin to octane, and pin the executor with tests including a
client-stub round-trip of Dates/Maps/Sets/undefined and a guard that the
encoding really is devalue, not plain JSON.
…dger

A separate package exploring how far "install a React package and use it
as-is" can go without AI. Three thin, extensible layers:
- shim: the react / react-dom / jsx-runtime a bridged package resolves to
  (absorbs forwardRef→refs-as-props, useDebugValue→no-op, react-dom re-home)
- codemod: import-reconciliation transforms (strip the builtin hooks the
  compiler re-injects; re-home the rest to the shim)
- detector: extensible rule registry over the MCP's REACT_API_MAP + the
  compiler's HOOK_NAMES; classifies bridgeable → needs-rework, emits an
  MCP work-list

8 graduated example "React packages" (E1 useState → E4 the wall → E7 Suspense
→ E8 reducer-store app). Tests bridge the unmodified React source through the
Octane compiler and mount it (11 runtime/detector), plus a differential oracle
asserting byte-equal DOM vs real React for 7 examples.

Adds a react-compat vitest project and an esbuild devDep for the React oracle.
Includes a runnable repro for a @tsrx/core parser bug found while bridging E5
(known-issues/), fixed upstream in Ripple-TS/ripple#1321.
… react-compat the default path

Two directions, one story:

- New @octanejs/react-wrapper: mount compiled Octane components inside a
  real React app (react/react-dom as peers). Props forward on every React
  commit through the Octane root's same-body fast path (Octane state,
  effects and DOM survive React re-renders); renders flush synchronously
  before paint; React children bridge into the Octane `children` hole via
  a stable-identity display:contents portal slot, so React state, context
  and events keep working inside Octane DOM and React → Octane → React
  nesting composes. wrapOctane() turns an Octane component into a
  first-class React component. StrictMode-safe teardown.

- @octanejs/react-compat is the out-of-the-box direction: the MCP bridge
  tool now reports runtime-compat verdicts (works-out-of-the-box /
  works-with-caveats / has-unsupported-apis), scans for legacy class
  lifecycles, and its plan leads with octane({ compat: [react()] }) —
  native @octanejs/* ports become the optional performance path. The
  bridge-react-package skill, MCP README/tool descriptions and the
  maintainer port skill are rewritten accordingly; the pre-runtime-compat
  framing in docs/react-library-compat-plan.md gets a status note.

Repo docs (README, RuleSync rules, project map) position the two packages
as one bi-directional bridge. Drops react-compat's unused esbuild devDep
(leftover from the deleted differential oracle).
- examples/octane-in-react: a real React app (react-dom, StrictMode,
  @vitejs/plugin-react) adopting Octane incrementally through
  @octanejs/react-wrapper — wrapped .tsrx counter driven by a React
  slider (props flow, Octane state survives), a React form rendered
  inside an Octane card via the children bridge, and a toggled Octane
  clock proving effect cleanup on unmount.

- examples/react-in-octane: an Octane app with no React installed
  running unmodified jotai (one atom shared by two islands) and
  react-hook-form (validation, watch, submit) through
  @octanejs/react-compat; islands authored as plain React .tsx via the
  automatic JSX runtime, crossing into .tsrx through resolveCompatType.

- octane/compiler/vite accepts tsx: false so React can own .tsx while
  octane compiles only .tsrx — the setup both mixed-renderer examples
  build on.

- react-wrapper split by responsibility: useOctaneRoot owns the Octane
  root lifecycle, useChildSlot owns the children bridge (the
  stable-descriptor invariant lives with it), index.ts is the public
  surface.

Both examples are verified end-to-end in Chromium: 13 interaction
assertions covering cross-renderer props, state survival, shared
package state, form semantics, and teardown.
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Error Error Jul 16, 2026 3:55pm

Request Review

@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 is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eb48020. Configure here.

{ cause },
);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suspense wrapper breaks fallback suspend

High Severity

The SSR Suspense facade catches every throw from OctaneSuspense and replaces it with a hard compatibility error. When a fallback itself suspends, Octane rethrows SSR_SUSPENSE so render() can await and retry; this wrapper turns that into a normal Error, so nested/fallback suspension fails the request instead of settling.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit eb48020. Configure here.

This branch was previously deployed

1 inactive deployment
Preview — eb480209 Deployed Jul 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant