Skip to content

Commit 0816832

Browse files
committed
refactor: use official async reference
1 parent 620e32b commit 0816832

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

examples/react-server/src/features/client-component/server.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ import type { BundlerConfig, ImportManifestEntry } from "../../types";
1010
// name: Counter
1111

1212
export function registerClientReference(id: string, name: string) {
13-
// reuse everything but $$async: true for simplicity
14-
const reference = ReactServer.registerClientReference({}, id, name);
15-
return Object.defineProperties(
16-
{},
17-
{
18-
...Object.getOwnPropertyDescriptors(reference),
19-
$$async: { value: true },
20-
},
21-
);
13+
return ReactServer.registerClientReference({}, id, name);
2214
}
2315

2416
export function createBundlerConfig(): BundlerConfig {
@@ -30,7 +22,12 @@ export function createBundlerConfig(): BundlerConfig {
3022
let [id, name] = $$id.split("#");
3123
tinyassert(id);
3224
tinyassert(name);
33-
return { id, name, chunks: [] } satisfies ImportManifestEntry;
25+
return {
26+
id,
27+
name,
28+
chunks: [],
29+
async: true,
30+
} satisfies ImportManifestEntry;
3431
},
3532
},
3633
);

examples/react-server/src/features/client-component/ssr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function createModuleMap(): ModuleMap {
4545
id,
4646
name,
4747
chunks: [],
48+
async: true,
4849
} satisfies ImportManifestEntry;
4950
},
5051
},

examples/react-server/src/features/server-action/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function createActionBundlerConfig(): BundlerConfig {
7878
id,
7979
name,
8080
chunks: [],
81+
async: true,
8182
} satisfies ImportManifestEntry;
8283
},
8384
},

examples/react-server/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
export interface ImportManifestEntry {
77
id: string;
88
name: string;
9-
// TODO
109
chunks: string[];
10+
async: boolean;
1111
}
1212

1313
export interface BundlerConfig {

examples/react-server/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ function vitePluginServerAction(): PluginOption {
373373

374374
// make server reference async for simplicity (stale chunkCache, etc...)
375375
// see TODO in https://github.com/facebook/react/blob/33a32441e991e126e5e874f831bd3afc237a3ecf/packages/react-server-dom-webpack/src/ReactFlightClientConfigBundlerWebpack.js#L131-L132
376-
code = code.replaceAll("if (isAsyncImport(metadata))", "if (true)");
377-
code = code.replaceAll("4 === metadata.length", "true");
376+
// code = code.replaceAll("if (isAsyncImport(metadata))", "if (true)");
377+
// code = code.replaceAll("4 === metadata.length", "true");
378378

379379
return { code, map: null };
380380
}

0 commit comments

Comments
 (0)