fix(server): wrap exported functions as hoisted declarations in action seed facade (#1208) - #1209
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1208
Problem
Two
'use server'modules that re-export from each other in a cycle crash at module load on Node and Bun:Root cause
The generated facade in
packages/server/src/action-seed.js(buildFacade()) rewrote every enumerated export as aexport const. While original JS function declarations (export async function ring()) are hoisted in ESM, converting them toexport constreplaced hoisting with a Temporal Dead Zone (TDZ). During circular evaluation, accessing__orig["ring"]whileringwas still uninitialized threw aReferenceError.Solution
extractExportNames()into function declarations / re-exports (fnNames) vs value constants (valNames).export function NAME(...args)definitions forfnNamesinbuildFacade(). Because function declarations are hoisted in ESM, the binding is defined before any top-level module code executes, resolving circular imports without TDZ errors.__w(file, name, name)immediately during module initialization to register action identity in_identityfor<form action=${action}>(Unify form submissions on <form action=${action}>, drop the page action export #1155).valNames, e.g.export const VERSION = '1.0') wrapped asexport const.Verification
node --test packages/server/test/seed/action-seed-unit.test.js: 18/18 pass.node --test packages/server/test/seed/seed-hook.test.js: 5/5 pass (including circular re-export test).bun test test/bun/action-seed-circular.test.mjs: 1/1 pass on Bun.node scripts/run-bun-tests.js: 272/272 pass (0 genuine failures).