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

Fix: Handle RSC errors #526

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
14 changes: 14 additions & 0 deletions src/setup-page-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ async function __getContext(storyId: string): Promise<any> {
return globalThis.__STORYBOOK_PREVIEW__.storyStore.loadStory({ storyId });
}

function isServerComponentError(error: unknown) {
return (
typeof error === 'string' &&
(error.includes('A component was suspended by an uncached promise.') ||
error.includes('async/await is not yet supported in Client Components'))
);
}

// @ts-expect-error Global main test function, used by the test runner
async function __test(storyId: string): Promise<any> {
try {
Expand Down Expand Up @@ -321,6 +329,12 @@ async function __test(storyId: string): Promise<any> {
const spyOnConsole = (method: ConsoleMethod, name: string): void => {
const originalFn = console[method].bind(console);
console[method] = function () {
const isConsoleError = method === 'error';
// Storybook nextjs/react supress error logs from server components and so should the test-runner
if (isConsoleError && isServerComponentError(arguments?.[0])) {
return;
}

const shouldCollectError = TEST_RUNNER_FAIL_ON_CONSOLE === 'true' && method === 'error';
if (shouldCollectError) {
hasErrors = true;
Expand Down
Loading