Skip to content

Commit 6501ca1

Browse files
committed
Add new error message for awaiting the client export
update test
1 parent a555419 commit 6501ca1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

packages/react-server-dom-turbopack/src/ReactFlightTurbopackReferences.js

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ const deepProxyHandlers = {
133133
`Instead, you can export a Client Component wrapper ` +
134134
`that itself renders a Client Context Provider.`,
135135
);
136+
case 'then':
137+
throw new Error(
138+
`Cannot await or return from a thenable. ` +
139+
`You cannot await a client module from a server component.`,
140+
);
136141
}
137142
// eslint-disable-next-line react-internal/safe-string-coercion
138143
const expression = String(target.name) + '.' + String(name);

packages/react-server-dom-webpack/src/ReactFlightWebpackReferences.js

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ const deepProxyHandlers = {
141141
`Instead, you can export a Client Component wrapper ` +
142142
`that itself renders a Client Context Provider.`,
143143
);
144+
case 'then':
145+
throw new Error(
146+
`Cannot await or return from a thenable. ` +
147+
`You cannot await a client module from a server component.`,
148+
);
144149
}
145150
// eslint-disable-next-line react-internal/safe-string-coercion
146151
const expression = String(target.name) + '.' + String(name);

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js

+13
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,19 @@ describe('ReactFlightDOM', () => {
623623
);
624624
});
625625

626+
it('throws when await a client module prop of client exports', () => {
627+
const ClientModule = clientExports({
628+
Component: function () {},
629+
});
630+
async function read() {
631+
return await ClientModule.then(mod => mod.Component);
632+
}
633+
expect(read).toThrowError(
634+
`Cannot await or return from a thenable. ` +
635+
`You cannot await a client module from a server component.`,
636+
);
637+
});
638+
626639
it('throws when accessing a symbol prop from client exports', () => {
627640
const symbol = Symbol('test');
628641
const ClientModule = clientExports({

0 commit comments

Comments
 (0)