Skip to content
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

refactor!: use ImportManifestEntry.async for async client reference module #643

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"@vitejs/plugin-react": "^4.3.1",
"@vitejs/plugin-react-swc": "^3.7.0",
"esbuild": "^0.23.0",
"react": "19.0.0-rc-eb3ad065-20240822",
"react-dom": "19.0.0-rc-eb3ad065-20240822",
"react-is": "19.0.0-rc-eb3ad065-20240822",
"react-server-dom-webpack": "19.0.0-rc-eb3ad065-20240822",
"react": "19.0.0-rc-f2df5694-20240916",
"react-dom": "19.0.0-rc-f2df5694-20240916",
"react-is": "19.0.0-rc-f2df5694-20240916",
"react-server-dom-webpack": "19.0.0-rc-f2df5694-20240916",
"tsup": "^8.1.0",
"tsx": "^4.16.2",
"typescript": "^5.5.4",
Expand Down
21 changes: 9 additions & 12 deletions packages/react-server/src/features/client-component/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ import type { BundlerConfig, ImportManifestEntry } from "../../types/react";

/* @__NO_SIDE_EFFECTS__ */
export function registerClientReference(id: string, name: string) {
// reuse everything but { $$async: true }.
// `$$async` is not strictly necessary if we use `__webpack_chunk_load__` trick
// but for now, we go with async `__webpack_require__` for simplicity.
const reference = ReactServer.registerClientReference({}, id, name);
return Object.defineProperties(
{},
{
...Object.getOwnPropertyDescriptors(reference),
$$async: { value: true },
},
);
return ReactServer.registerClientReference({}, id, name);
}

export function createBundlerConfig(): BundlerConfig {
Expand All @@ -33,7 +23,14 @@ export function createBundlerConfig(): BundlerConfig {
let [id, name] = $$id.split("#");
tinyassert(id);
tinyassert(name);
return { id, name, chunks: [] } satisfies ImportManifestEntry;
return {
id,
name,
chunks: [],
// `async` is not strictly necessary if we use `__webpack_chunk_load__` trick
// but for now, going with async `__webpack_require__` seems simpler.
async: true,
} satisfies ImportManifestEntry;
},
},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/types/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
export interface ImportManifestEntry {
id: string;
name: string;
// TODO
chunks: string[];
async?: boolean;
}

export interface BundlerConfig {
Expand Down
Loading