Skip to content

fix(server): wrap exported functions as hoisted declarations in action seed facade (#1208) - #1209

Merged
vivek7405 merged 2 commits into
mainfrom
fix/action-seed-circular-reexport
Aug 1, 2026
Merged

fix(server): wrap exported functions as hoisted declarations in action seed facade (#1208)#1209
vivek7405 merged 2 commits into
mainfrom
fix/action-seed-circular-reexport

Conversation

@vivek7405

@vivek7405 vivek7405 commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #1208

Problem

Two 'use server' modules that re-export from each other in a cycle crash at module load on Node and Bun:

ReferenceError: Cannot access 'ring' before initialization

Root cause

The generated facade in packages/server/src/action-seed.js (buildFacade()) rewrote every enumerated export as a export const. While original JS function declarations (export async function ring()) are hoisted in ESM, converting them to export const replaced hoisting with a Temporal Dead Zone (TDZ). During circular evaluation, accessing __orig["ring"] while ring was still uninitialized threw a ReferenceError.

Solution

  1. Categorize exported symbols in extractExportNames() into function declarations / re-exports (fnNames) vs value constants (valNames).
  2. Generate hoisted export function NAME(...args) definitions for fnNames in buildFacade(). Because function declarations are hoisted in ESM, the binding is defined before any top-level module code executes, resolving circular imports without TDZ errors.
  3. Call __w(file, name, name) immediately during module initialization to register action identity in _identity for <form action=${action}> (Unify form submissions on <form action=${action}>, drop the page action export #1155).
  4. Keep non-function value constants (valNames, e.g. export const VERSION = '1.0') wrapped as export const.

Verification

  • Unit test suite node --test packages/server/test/seed/action-seed-unit.test.js: 18/18 pass.
  • Load hook integration test node --test packages/server/test/seed/seed-hook.test.js: 5/5 pass (including circular re-export test).
  • Bun parity test bun test test/bun/action-seed-circular.test.mjs: 1/1 pass on Bun.
  • Full Bun test matrix node scripts/run-bun-tests.js: 272/272 pass (0 genuine failures).

@vivek7405
vivek7405 merged commit fc103ab into main Aug 1, 2026
10 checks passed
@vivek7405
vivek7405 deleted the fix/action-seed-circular-reexport branch August 1, 2026 12:53
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.

Circular re-export between two use-server modules crashes at load

1 participant