Skip to content

fix(bindings): fix published source a browser app cannot type-check - #734

Merged
trueadm merged 10 commits into
octanejs:mainfrom
dudusotero:fix/binding-consumer-types
Aug 12, 2026
Merged

trueadm merged 10 commits into
octanejs:mainfrom
dudusotero:fix/binding-consumer-types

Conversation

@dudusotero

@dudusotero dudusotero commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #732. GitHub cannot base a fork PR on another fork branch, so the diff below also contains #732's commits. Review only fix(bindings): fix published source a browser app cannot type-check (9 files, +65/-5).

Scoped to avoid overlapping #733. That PR fixes the Provider prop typings in jotai and redux; this one leaves those files alone and fixes what #733 does not touch. There is no file in common between the two.

These packages ship raw source and point their exports at it, so a consumer's TypeScript program compiles every reachable module.

process is not available to a browser application. Published source referenced the bare process.env.NODE_ENV global in four modules. A scaffolded Octane app has no @types/node, so each one is a consumer-visible error. #733's browser lane includes node_modules/@octanejs/**/*.tsrx, so these .ts modules are not the files it compiles directly.

The obvious fix is wrong, which is worth stating because it looks right. Reading the value through globalThis type-checks, but a bundler's define substitution matches the literal text process.env.NODE_ENV, and the dead-code elimination that follows removes the dev-only branch. Losing both would drop dev warnings under Vite and grow every consumer's production bundle. A module-local declare const process keeps the expression written out literally, so both still work, and nothing ambient ships in the tarball. Verified with esbuild:

$ esbuild probe.ts --bundle --define:process.env.NODE_ENV='"production"' --minify
var o=!1;function n(){}export{o as ENABLE_DEV_WARNINGS,n as warn};

Form and Link rejected a forwarded ref. Both accepted ref typed as possibly undefined. The compiler composes a forwarded ref with the host spread's ref as ref={[ref, spread.ref]}, and members of a Ref<T> array cannot be undefined. They now accept null, which attachRef already treats as absent via its leading if (ref == null) return;.

packages/remix-router/src/lib/router/utils.ts is vendored and must not be hand-edited, so the same deviation is carried into scripts/vendor-remix-router.mjs. Its note text is deliberately unchanged: the note is interpolated into the generated file header, so editing it would break the byte-for-byte round trip.

Refs #721.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted tests:
    • pnpm vitest run --project jotai --project jotai-differential --project redux --project redux-differential --project remix-router --project remix-router-ssr --project remix-router-core --project remix-router-differential (33 files, 324 tests, all passing)
    • pnpm exec tsrx-tsc --noEmit -p packages/remix-router/tsconfig.json (0 errors)
    • pnpm changeset:check

format:check and typecheck were run with unrelated in-progress work removed from the tree, so they reflect this stack alone.

pnpm test was not run in full. It was run earlier over the whole working tree: 5 test files failed out of 2301, all pre-existing on this base. Running the same 5 projects against a clean origin/main checkout gives 17 failing tests versus 16 here, and none touch a package this PR changes.

Risk / follow-ups

jotai and redux are not promoted from tsgo onto tsrx-tsc here, and keep their SOURCE_PUBLICATION_DEBT entries, so this PR's diff stays what was reviewed.

That is now the only thing holding the promotion back. #733 has merged, so with this branch on top all three packages report zero diagnostics under tsrx-tsc against their own tsconfig, measured just now: jotai 0, redux 0, remix-router 0. Promoting the two and dropping their entries is a small follow-up once this and #732 land, and #732's guardrail will reject the entries as stale at that point.

No runtime test forwards a ref to <Form> or <Link>, so that change rests on attachRef's existing null guard and an unchanged suite rather than on direct coverage. Worth adding.

Provenance

  • An agent produced this diff (agent-authored)

Note

Low Risk
Binding edits are typings and ref defaults with unchanged runtime behavior; broader script/tsconfig changes affect CI validation, not shipped app runtime.

Overview
Fixes consumer-visible TypeScript errors in @octanejs/jotai, @octanejs/redux, and @octanejs/remix-router, which ship raw src/ into app typecheck graphs.

process.env.NODE_ENV in published modules now uses a module-local declare const process so browser apps without @types/node compile, while keeping the literal expression for bundler define / dead-code elimination. Applied in jotai hooks/utils, redux hooks, remix-router utils.ts, and the vendor script that regenerates that file.

Form and Link now type ref as null | Ref with ref = null default, fixing forwarded-ref composition as ref={[forwarded, spread.ref]} where array members cannot be undefined.

Also adds source-publication guardrails (stacked work): check-source-publication.mjs with a shrinking debt allowlist, consumer-shaped tsconfig generation under scripts/consumer-tsconfigs/, and root typecheck / bindings:typecheck updates so more bindings use tsrx-tsc instead of tsgo on .tsrx. Patch changesets for the three binding packages.

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

Packages that ship .tsrx were typechecked by tsgo, which drops those
files from the program entirely. Their published source was therefore
never checked at all. Bindings publish raw source and point exports at
it, so every one of those errors is visible to a consumer.

- Generate canonical consumer projects from the same tsconfig the CLI
  scaffolds, with a drift check, so what is validated cannot diverge
  from what users actually compile against.
- Move the .tsrx-publishing projects that already pass onto tsrx-tsc.
- Add a no-@types/node lane to the packed-tarball canary. The existing
  lane sets types: ["node"], so it cannot see `process` references in
  published source, which a browser app does not resolve.
- Add a guardrail over source-published packages with an enumerated
  allowlist of the remaining violations. A stale entry fails the check,
  so the list can only shrink.
octanejs#733 rebuilds the packed TSRX consumer canary around automatic discovery
of every binding that ships .tsrx, which is a better answer than the
package list this branch was extending. Drop the overlapping edits to
package-pack-canaries.mjs, check-package-packs.mjs and their test so the
two branches stop touching the same files.

What remains here is the part octanejs#733 does not cover: the root typecheck
chain still runs tsgo over packages that ship .tsrx, so those files are
absent from the program CI actually runs.
These packages ship raw source and point exports at it, so a consumer's
program compiles every reachable module. The repo checked them with tsgo,
which drops .tsrx from the program, so none of this was visible in CI
while all of it was visible to consumers.

- Declare `process` module-locally at every published
  `process.env.NODE_ENV` reference. A browser app has no @types/node. The
  expression stays written out literally so bundler define substitution
  and the dead-code elimination after it are unaffected, and nothing
  ambient ships in the tarball.
- Let Form and Link accept a null forwarded ref: the compiler composes it
  as ref={[ref, spread.ref]}, and Ref<T> array members cannot be undefined.
- Carry the same process deviation into the remix-router vendoring script,
  so a re-vendor does not reintroduce the error.

The Provider prop typings for jotai and redux are left to octanejs#733, which
edits the same two files.
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Aug 12, 2026
Two defects Cursor Bugbot found on this PR, both confirmed.

The nodeTypes and excluded rules only saw projects discovered by parsing
inline compiler invocations out of the root typecheck chain. A package
validated through a package script, a node wrapper, or absent from the
chain never entered the loop, so the gate stayed green while missing the
defect it claims to block. They now walk each source-published package's
own tsconfigs; the tsgo rule still follows the chain, since that rule
genuinely is a claim about what the chain runs.

The excluded rule matched an exclude entry only when it named a shipped
file exactly, so `src`, `src/**` or `src/**/*.tsrx` could drop packed
source without tripping it. Exclude entries are now translated into path
predicates following tsc's own wildcard shape.

The allowlist grows from 100 to 112. All twelve additions are
node-types-in-validation-tsconfig entries that chain-only discovery could
not see, including the four Bugbot named. The previous number was not the
real debt, only the part the gate could reach.
Third Bugbot finding, confirmed. The trailing `($|/)` was appended to every
pattern, so a wildcard final segment behaved like a directory prefix:
`src/*` matched `src/a/b/deep.ts` and `*` matched `src/a/b.ts`, where tsc's
`*` and `?` do not cross `/`.

Only a literal final segment, or `**` whose `.*` already spans, keeps the
directory suffix now. Totals are unchanged at 112; no current entry depended
on the over-match.
@dudusotero
dudusotero marked this pull request as ready for review August 12, 2026 20:18
@trueadm
trueadm merged commit ce3a6fe into octanejs:main Aug 12, 2026
46 checks passed
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.

2 participants