Skip to content

fix(seo): compile and run the published source outside Node - #954

Merged
trueadm merged 1 commit into
mainfrom
fix/seo-consumer-source
Sep 5, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/seo-consumer-source

Conversation

@WebEferen

@WebEferen WebEferen commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@octanejs/seo publishes src/, so an application compiles these files with its own tsconfig and runs them in its own host. Both halves were broken.

It does not compile without Node types. This is the repo's own consumer project, scripts/consumer-tsconfigs/seo.json, on main:

packages/seo/src/useStrayOwnerDiagnostic.ts(23,6): error TS2591: Cannot find name 'process'.

The package tsconfig pins types: ["node"], which hid it in here. And it is not only a type error: a browser has no process, so any host that does not substitute the read threw a ReferenceError out of every <Head> render, in place of a development-only check. The reference is now declared locally and guarded with typeof, following packages/lynx/src/core/environment.ts. It stays spelled out as process.env.NODE_ENV so bundler defines still fold it.

One trade-off worth naming: where a bundler substitutes the value but leaves no process global, the guard reads false and the diagnostic behaves as it does in development, one counter and one effect per owning <Head>. That is the price of not throwing, and it is the arrangement React-ecosystem packages end up in too.

It does not compile under exactOptionalPropertyTypes or noUncheckedIndexedAccess, which plenty of applications turn on:

packages/seo/src/components.tsrx(210,35): error TS2379: Argument of type
  '{ site: string | undefined; titleTemplate: string | undefined; ... }' is not
  assignable to parameter of type 'SeoConfig' with 'exactOptionalPropertyTypes: true'.
packages/seo/src/expand.ts(152,16): error TS18048: 'image' is possibly 'undefined'.   (+8 more)
packages/seo/src/registry.ts(43,7):  error TS18048: 'x' is possibly 'undefined'.      (+7 more)

SeoConfig's fields now admit undefined alongside being optional, which is what they have always meant: applyConfig and the registry merge read each one with an !== undefined test, so an absent key and a present undefined are the same thing, and <Seo> can go on forwarding its optional props in one expression. The two loops that index an array they just measured say so.

Found while building an Octane app. It was shipping a pnpm patch against the published tarball; this is the same fix upstream.

Validation

Repo-wide pnpm typecheck and pnpm test were not run.

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted: tsrx-tsc -p packages/seo/tsconfig.json, vitest run --project "*seo*" (11 files, 105 tests)
  • tsrx-tsc -p scripts/consumer-tsconfigs/seo.json now passes; it fails on main with the error above
  • same project plus exactOptionalPropertyTypes and noUncheckedIndexedAccess reports nothing from this package
  • the new test fails when the production guard is deleted

The no-process path has no runtime test. vi.stubGlobal('process', undefined) takes the Vitest worker down with it (Cannot set properties of undefined (setting 'nextTick')), so the crash is covered by the consumer typecheck and by the guard being a typeof test. The new test pins the other half, the production skip, which the rewritten guard could have dropped silently.

Risk / follow-ups

SeoConfig is exported, so the widened fields are a public type change. It only accepts more, and no consumer expression stops compiling.

The strict-flag half has no gate. scripts/consumer-tsconfigs/base.json mirrors what octane init scaffolds, which leaves both flags off, and turning them on in a package tsconfig pulls packages/octane/src into the program, where the same classes of error exist in bulk. A real consumer never sees those, because octane publishes dist with declarations behind skipLibCheck, while every @octanejs/* binding publishes source. The header of scripts/generate-consumer-tsconfigs.mjs already records that debt against #721; widening those projects is worth doing once core is clean.

Provenance

  • An agent produced this diff (agent-authored)

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


Note

Low Risk
Mostly typing and a dev-only diagnostic guard; exported SeoConfig widens acceptably, with no intended runtime behavior change for apps that already built.

Overview
@octanejs/seo ships source, so consumer apps compile it with their own tsconfig and run it in browser hosts. This PR fixes compile-time and runtime failures that only showed up there.

useStrayOwnerDiagnostic no longer assumes Node: it declares process locally and guards with typeof process !== 'undefined' before reading process.env.NODE_ENV, so builds without @types/node typecheck and hosts without a process global stop throwing on every <Head> render. The expression stays process.env.NODE_ENV so bundlers can still inline production.

Strict TypeScript consumers get type-only fixes: SeoConfig fields explicitly allow undefined (matching existing !== undefined merge semantics under exactOptionalPropertyTypes), and indexed array reads in expand.ts / registry.ts use non-null assertions under noUncheckedIndexedAccess. A test asserts the stray-<Head> diagnostic stays off when NODE_ENV is production.

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

The package ships `src/`, so an application compiles these files with its own
tsconfig and runs them in its own host. `useStrayOwnerDiagnostic` read
`process.env.NODE_ENV` with nothing declaring `process`: the package tsconfig
pins `types: ["node"]` and hid it, while a browser application has neither the
types nor the global, so the file failed to compile and threw a ReferenceError
out of every <Head> render wherever nothing substituted the read.

The remaining errors were `exactOptionalPropertyTypes` and
`noUncheckedIndexedAccess`. `SeoConfig` now admits `undefined` alongside
optional, matching what the merge has always done with it, and the two loops
that index an array they just measured say so.

Behavior is unchanged for an application that already built. The new test pins
the production skip, which is the part of the diagnostic the rewritten guard
could have dropped.
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 4, 2026
@trueadm
trueadm marked this pull request as ready for review September 5, 2026 17:26
@trueadm
trueadm merged commit 395ebe8 into main Sep 5, 2026
51 checks passed
@trueadm
trueadm deleted the fix/seo-consumer-source branch September 5, 2026 18:29
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