mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Fix error handling in resolveClientReference (#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.
This commit is contained in:
+3
-3
@@ -62,19 +62,19 @@ export function resolveClientReference<T>(
|
||||
metadata: ClientReferenceMetadata,
|
||||
): ClientReference<T> {
|
||||
const moduleExports = bundlerConfig[metadata[ID]];
|
||||
let resolvedModuleData = moduleExports[metadata[NAME]];
|
||||
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
|
||||
let name;
|
||||
if (resolvedModuleData) {
|
||||
// The potentially aliased name.
|
||||
name = resolvedModuleData.name;
|
||||
} else {
|
||||
// If we don't have this specific name, we might have the full module.
|
||||
resolvedModuleData = moduleExports['*'];
|
||||
resolvedModuleData = moduleExports && moduleExports['*'];
|
||||
if (!resolvedModuleData) {
|
||||
throw new Error(
|
||||
'Could not find the module "' +
|
||||
metadata[ID] +
|
||||
'" in the React SSR Manifest. ' +
|
||||
'" in the React Server Consumer Manifest. ' +
|
||||
'This is probably a bug in the React Server Components bundler.',
|
||||
);
|
||||
}
|
||||
|
||||
+3
-3
@@ -68,19 +68,19 @@ export function resolveClientReference<T>(
|
||||
): ClientReference<T> {
|
||||
if (bundlerConfig) {
|
||||
const moduleExports = bundlerConfig[metadata[ID]];
|
||||
let resolvedModuleData = moduleExports[metadata[NAME]];
|
||||
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
|
||||
let name;
|
||||
if (resolvedModuleData) {
|
||||
// The potentially aliased name.
|
||||
name = resolvedModuleData.name;
|
||||
} else {
|
||||
// If we don't have this specific name, we might have the full module.
|
||||
resolvedModuleData = moduleExports['*'];
|
||||
resolvedModuleData = moduleExports && moduleExports['*'];
|
||||
if (!resolvedModuleData) {
|
||||
throw new Error(
|
||||
'Could not find the module "' +
|
||||
metadata[ID] +
|
||||
'" in the React SSR Manifest. ' +
|
||||
'" in the React Server Consumer Manifest. ' +
|
||||
'This is probably a bug in the React Server Components bundler.',
|
||||
);
|
||||
}
|
||||
|
||||
+3
-3
@@ -62,19 +62,19 @@ export function resolveClientReference<T>(
|
||||
metadata: ClientReferenceMetadata,
|
||||
): ClientReference<T> {
|
||||
const moduleExports = bundlerConfig[metadata[ID]];
|
||||
let resolvedModuleData = moduleExports[metadata[NAME]];
|
||||
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
|
||||
let name;
|
||||
if (resolvedModuleData) {
|
||||
// The potentially aliased name.
|
||||
name = resolvedModuleData.name;
|
||||
} else {
|
||||
// If we don't have this specific name, we might have the full module.
|
||||
resolvedModuleData = moduleExports['*'];
|
||||
resolvedModuleData = moduleExports && moduleExports['*'];
|
||||
if (!resolvedModuleData) {
|
||||
throw new Error(
|
||||
'Could not find the module "' +
|
||||
metadata[ID] +
|
||||
'" in the React SSR Manifest. ' +
|
||||
'" in the React Server Consumer Manifest. ' +
|
||||
'This is probably a bug in the React Server Components bundler.',
|
||||
);
|
||||
}
|
||||
|
||||
+3
-3
@@ -68,19 +68,19 @@ export function resolveClientReference<T>(
|
||||
): ClientReference<T> {
|
||||
if (bundlerConfig) {
|
||||
const moduleExports = bundlerConfig[metadata[ID]];
|
||||
let resolvedModuleData = moduleExports[metadata[NAME]];
|
||||
let resolvedModuleData = moduleExports && moduleExports[metadata[NAME]];
|
||||
let name;
|
||||
if (resolvedModuleData) {
|
||||
// The potentially aliased name.
|
||||
name = resolvedModuleData.name;
|
||||
} else {
|
||||
// If we don't have this specific name, we might have the full module.
|
||||
resolvedModuleData = moduleExports['*'];
|
||||
resolvedModuleData = moduleExports && moduleExports['*'];
|
||||
if (!resolvedModuleData) {
|
||||
throw new Error(
|
||||
'Could not find the module "' +
|
||||
metadata[ID] +
|
||||
'" in the React SSR Manifest. ' +
|
||||
'" in the React Server Consumer Manifest. ' +
|
||||
'This is probably a bug in the React Server Components bundler.',
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user