Skip to content

fix(platform): construct NodeCompatibleFileSystemAdapter safely when node:fs constants are absent - #3672

Merged
kojiwakayama merged 2 commits into
mainfrom
fix/nodefs-ofollow-browser-safe
Aug 13, 2026
Merged

fix(platform): construct NodeCompatibleFileSystemAdapter safely when node:fs constants are absent#3672
kojiwakayama merged 2 commits into
mainfrom
fix/nodefs-ofollow-browser-safe

Conversation

@mattboon

@mattboon mattboon commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Bug

NodeCompatibleFileSystemAdapter's constructor reads a node:fs constant unconditionally:

const noFollow = hasOwn(options, "noFollow") ? options.noFollow : nodeFsConstants.O_NOFOLLOW;

In a non-Node runtime (e.g. a browser bundle that transitively imports this adapter), nodeFsConstants is undefined, so construction throws:

TypeError: Cannot read properties of undefined (reading 'O_NOFOLLOW')
    at new NodeCompatibleFileSystemAdapter (…/node-filesystem-adapter.js)
    at new DenoFileSystemAdapter (…/deno/filesystem-adapter.js)
    at new DenoAdapter (…/deno/adapter.js)

…which aborts client hydration.

Issue

Surfaced by #3661 (a client-tree route that value-imports a server helper drags the runtime adapter graph into the browser bundle). Whether or not that leak should happen, the adapter constructor should not crash when node:fs constants are unavailable — the code already models this: NodeFileSystemCapabilityOptions.noFollow is documented as "An own undefined value means unavailable."

Reproduction

Against this repo's source via LOCALDEV, pages-server-import-leak/vector-a in mattboon/veryfront-router-testing:

cd pages-server-import-leak
deno run --allow-all <veryfront-code>/cli/main.ts dev --port 3025
# open http://127.0.0.1:3025/vector-a → console shows the O_NOFOLLOW TypeError, hydration aborts

Fix

Optional-chain the constant deref, matching the documented "undefined means unavailable" contract. When absent, noFollow is undefinedcanOpenExactSnapshot is false (correct in a browser), and the constructor no longer throws.

-    const noFollow = hasOwn(options, "noFollow") ? options.noFollow : nodeFsConstants.O_NOFOLLOW;
+    const noFollow = hasOwn(options, "noFollow")
+      ? options.noFollow
+      : nodeFsConstants?.O_NOFOLLOW;

Validation

deno test src/platform/adapters/runtime/shared/node-filesystem-adapter.test.ts1 passed (37 steps), 0 failed.

Defense-in-depth only: the deeper server→client leak that pulls this adapter into the browser at all is tracked separately in #3661.

Refs #3661.

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with runtimes where certain filesystem options are unavailable.
    • Prevented initialization errors in environments that do not provide the optional filesystem constant.

…node:fs constants are absent

Guard the `node:fs` constants deref so the adapter constructor doesn't throw in
a non-Node runtime (e.g. a browser bundle that transitively imports it).

Refs #3661.
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mattboon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9295e18f-361e-47db-9072-8595b302223c

📥 Commits

Reviewing files that changed from the base of the PR and between fd50d50 and d884bb6.

📒 Files selected for processing (2)
  • src/platform/adapters/runtime/shared/node-filesystem-adapter.test.ts
  • src/platform/adapters/runtime/shared/node-filesystem-adapter.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 94ac7d8a-c530-416a-a375-42972b0030f8

📥 Commits

Reviewing files that changed from the base of the PR and between 76ef22c and fd50d50.

📒 Files selected for processing (1)
  • src/platform/adapters/runtime/shared/node-filesystem-adapter.ts

📝 Walkthrough

Walkthrough

The filesystem adapter constructor now treats unavailable nodeFsConstants.O_NOFOLLOW values as unavailable instead of throwing during construction.

Changes

Filesystem capability handling

Layer / File(s) Summary
Optional O_NOFOLLOW lookup
src/platform/adapters/runtime/shared/node-filesystem-adapter.ts
The constructor uses optional chaining when reading nodeFsConstants.O_NOFOLLOW.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Mergeability Score: ⚪ Minimal · up to fd50d

The change prevents adapter construction from crashing in runtimes without node:fs constants while preserving unavailable no-follow behavior; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

Suggested reviewers: kwakayama, kojiwakayama

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the constructor fix for runtimes without node:fs constants.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nodefs-ofollow-browser-safe

Comment @coderabbitai help to get the list of available commands.

… resolver

Extract the default-noFollow resolution into `resolveNoFollowFlag(options,
constants)` so the "constants unavailable" branch is testable without a
`node:fs` mock: passing `undefined` for `constants` reproduces a non-Node
runtime directly. Without the guard it throws `Cannot read properties of
undefined (reading 'O_NOFOLLOW')`; with it, the flag degrades to `undefined`.

Adds unit tests for the resolver (absent / present / own-seam) and an
adapter-construction test asserting it builds without exact-snapshot support
when the constants are absent.

Refs #3661.
@kojiwakayama
kojiwakayama added this pull request to the merge queue Aug 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 13, 2026
@kojiwakayama
kojiwakayama added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit 0361d07 Aug 13, 2026
33 checks passed
@kojiwakayama
kojiwakayama deleted the fix/nodefs-ofollow-browser-safe branch August 13, 2026 23:38
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.

2 participants