Skip to content

Commit 2dc5beb

Browse files
authored
Fix error handling in resolveClientReference (facebook#31332)
When a React Server Consumer Manifest does not include an entry for a client reference ID, we must not try to look up the export name (or `'*'`) for the client reference. Otherwise this will fail with `TypeError: Cannot read properties of undefined (reading '...')` instead of the custom error we intended to throw.
1 parent b4cbdc5 commit 2dc5beb

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

packages/react-server-dom-turbopack/src/client/ReactFlightClientConfigBundlerNode.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ export function resolveClientReference<T>(
6262
metadata: ClientReferenceMetadata,
6363
): ClientReference<T> {
6464
const moduleExports = bundlerConfig[metadata[ID]];
65-
let resolvedModuleData = moduleExports[metadata[NAME]];
65+
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
6666
let name;
6767
if (resolvedModuleData) {
6868
// The potentially aliased name.
6969
name = resolvedModuleData.name;
7070
} else {
7171
// If we don't have this specific name, we might have the full module.
72-
resolvedModuleData = moduleExports['*'];
72+
resolvedModuleData = moduleExports && moduleExports['*'];
7373
if (!resolvedModuleData) {
7474
throw new Error(
7575
'Could not find the module "' +
7676
metadata[ID] +
77-
'" in the React SSR Manifest. ' +
77+
'" in the React Server Consumer Manifest. ' +
7878
'This is probably a bug in the React Server Components bundler.',
7979
);
8080
}

packages/react-server-dom-turbopack/src/client/ReactFlightClientConfigBundlerTurbopack.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ export function resolveClientReference<T>(
6868
): ClientReference<T> {
6969
if (bundlerConfig) {
7070
const moduleExports = bundlerConfig[metadata[ID]];
71-
let resolvedModuleData = moduleExports[metadata[NAME]];
71+
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
7272
let name;
7373
if (resolvedModuleData) {
7474
// The potentially aliased name.
7575
name = resolvedModuleData.name;
7676
} else {
7777
// If we don't have this specific name, we might have the full module.
78-
resolvedModuleData = moduleExports['*'];
78+
resolvedModuleData = moduleExports && moduleExports['*'];
7979
if (!resolvedModuleData) {
8080
throw new Error(
8181
'Could not find the module "' +
8282
metadata[ID] +
83-
'" in the React SSR Manifest. ' +
83+
'" in the React Server Consumer Manifest. ' +
8484
'This is probably a bug in the React Server Components bundler.',
8585
);
8686
}

packages/react-server-dom-webpack/src/client/ReactFlightClientConfigBundlerNode.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ export function resolveClientReference<T>(
6262
metadata: ClientReferenceMetadata,
6363
): ClientReference<T> {
6464
const moduleExports = bundlerConfig[metadata[ID]];
65-
let resolvedModuleData = moduleExports[metadata[NAME]];
65+
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
6666
let name;
6767
if (resolvedModuleData) {
6868
// The potentially aliased name.
6969
name = resolvedModuleData.name;
7070
} else {
7171
// If we don't have this specific name, we might have the full module.
72-
resolvedModuleData = moduleExports['*'];
72+
resolvedModuleData = moduleExports && moduleExports['*'];
7373
if (!resolvedModuleData) {
7474
throw new Error(
7575
'Could not find the module "' +
7676
metadata[ID] +
77-
'" in the React SSR Manifest. ' +
77+
'" in the React Server Consumer Manifest. ' +
7878
'This is probably a bug in the React Server Components bundler.',
7979
);
8080
}

packages/react-server-dom-webpack/src/client/ReactFlightClientConfigBundlerWebpack.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ export function resolveClientReference<T>(
6868
): ClientReference<T> {
6969
if (bundlerConfig) {
7070
const moduleExports = bundlerConfig[metadata[ID]];
71-
let resolvedModuleData = moduleExports[metadata[NAME]];
71+
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
7272
let name;
7373
if (resolvedModuleData) {
7474
// The potentially aliased name.
7575
name = resolvedModuleData.name;
7676
} else {
7777
// If we don't have this specific name, we might have the full module.
78-
resolvedModuleData = moduleExports['*'];
78+
resolvedModuleData = moduleExports && moduleExports['*'];
7979
if (!resolvedModuleData) {
8080
throw new Error(
8181
'Could not find the module "' +
8282
metadata[ID] +
83-
'" in the React SSR Manifest. ' +
83+
'" in the React Server Consumer Manifest. ' +
8484
'This is probably a bug in the React Server Components bundler.',
8585
);
8686
}

0 commit comments

Comments
 (0)