Skip to content

Commit

Permalink
Add new error message for awaiting the client export
Browse files Browse the repository at this point in the history
update test
  • Loading branch information
huozhi committed Jun 20, 2024
1 parent a555419 commit 6501ca1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ const deepProxyHandlers = {
`Instead, you can export a Client Component wrapper ` +
`that itself renders a Client Context Provider.`,
);
case 'then':
throw new Error(
`Cannot await or return from a thenable. ` +
`You cannot await a client module from a server component.`,
);
}
// eslint-disable-next-line react-internal/safe-string-coercion
const expression = String(target.name) + '.' + String(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ const deepProxyHandlers = {
`Instead, you can export a Client Component wrapper ` +
`that itself renders a Client Context Provider.`,
);
case 'then':
throw new Error(
`Cannot await or return from a thenable. ` +
`You cannot await a client module from a server component.`,
);
}
// eslint-disable-next-line react-internal/safe-string-coercion
const expression = String(target.name) + '.' + String(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,19 @@ describe('ReactFlightDOM', () => {
);
});

it('throws when await a client module prop of client exports', () => {
const ClientModule = clientExports({
Component: function () {},
});
async function read() {
return await ClientModule.then(mod => mod.Component);
}
expect(read).toThrowError(
`Cannot await or return from a thenable. ` +
`You cannot await a client module from a server component.`,
);
});

it('throws when accessing a symbol prop from client exports', () => {
const symbol = Symbol('test');
const ClientModule = clientExports({
Expand Down

0 comments on commit 6501ca1

Please sign in to comment.