-
-
Notifications
You must be signed in to change notification settings - Fork 159
fix(streams,transform): Node tick parity — tee/pipe cadence + awaits trapped in the object-spread IIFE (Next.js Flight byte-parity) #6657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
proggeramlug
merged 2 commits into
PerryTS:main
from
proggeramlug:fix/tee-cold-start-cadence
Jul 19, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // An async function whose awaits sit inside an object literal WITH a spread | ||
| // must still suspend at the await and return a pending promise immediately — | ||
| // like V8 — instead of blocking the frame on the microtask pump. | ||
| // | ||
| // `{ v: await p, ...src }` lowers to a synthetic IIFE (`__perry_obj_iife`); | ||
| // two transform gaps left such functions un-CPS-rewritten: the hoist pre-pass | ||
| // never descended into the IIFE, and — for NESTED async closures (the | ||
| // turbopack factory shape) — the collect scan's closure-stop meant a function | ||
| // whose ONLY awaits sat in the IIFE never entered the work set at all. The | ||
| // resulting mid-frame drain reordered every promise race against the object | ||
| // build (the Next.js Flight row swap: next-intl's provider wrapper is exactly | ||
| // this shape). | ||
| // | ||
| // Detector: a properly-suspending call lets "after-call" log BEFORE the | ||
| // resolver tick; a busy-waiting call pumps the queue inside itself, flipping | ||
| // the order. | ||
|
|
||
| function scenario(name: string, makeCall: (p: Promise<string>) => any) { | ||
| return new Promise<void>((done) => { | ||
| let r: (v: string) => void; | ||
| const pending = new Promise<string>((res) => (r = res)); | ||
| const log: string[] = []; | ||
| Promise.resolve().then(() => { | ||
| log.push("tick1"); | ||
| r!("V"); | ||
| }); | ||
| const ret = makeCall(pending); | ||
| log.push("after-call"); | ||
| Promise.resolve(ret).then((v) => { | ||
| log.push("resolved " + JSON.stringify(v)); | ||
| console.log(name + ": " + log.join(" | ")); | ||
| done(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function f1(p: Promise<string>) { | ||
| return await p; | ||
| } | ||
|
|
||
| function jsx(t: string, props: Record<string, unknown>) { | ||
| return { t, props }; | ||
| } | ||
|
|
||
| const src = { x: 1 }; | ||
|
|
||
| // Top-level async fn, spread after/before the await. | ||
| async function spreadAfter(p: Promise<string>) { | ||
| return { v: await p, ...src }; | ||
| } | ||
| async function spreadBefore(p: Promise<string>) { | ||
| return { ...src, v: await p }; | ||
| } | ||
|
|
||
| // The production shape: NESTED async fn (factory arrow), conditional awaits | ||
| // in an object argument with a rest-spread that shadows the fn name. | ||
| const reg: { m?: (o: any) => Promise<any> } = {}; | ||
| ((a: typeof reg) => { | ||
| async function m({ formats, locale, p, ...m }: any) { | ||
| return jsx("g", { | ||
| formats: void 0 === formats ? await f1(p) : formats, | ||
| locale: locale ?? (await f1(p)), | ||
| ...m, | ||
| }); | ||
| } | ||
| a.m = m; | ||
| })(reg); | ||
|
|
||
| async function main() { | ||
| await scenario("top-level-spread-after", (p) => spreadAfter(p)); | ||
| await scenario("top-level-spread-before", (p) => spreadBefore(p)); | ||
| await scenario("nested-factory-conditional-awaits", (p) => | ||
| reg.m!({ p, extra: 2 }), | ||
| ); | ||
| console.log("DONE"); | ||
| } | ||
|
|
||
| main(); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 10724
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 42124
Replay
Stmt::Letbodies too__perry_obj_iifelowering emitsStmt::Letinits, so the_arm can leave awaits inside those initializers unhoisted. Recurse throughLet::init(or hoist them here) before pushing the stmt.🤖 Prompt for AI Agents