From 137a63b90d56d9c8de870738b0f6c4eca43e6e9b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 16 Dec 2022 17:47:30 +0100 Subject: [PATCH] Fix ignoring dev warning for preload component (#44065) Fix ignoring warning added in #41519 --- packages/next/server/app-render.tsx | 2 +- test/e2e/app-dir/index.test.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/next/server/app-render.tsx b/packages/next/server/app-render.tsx index 193b23526fe8a68..5a1bd0f5c45dd59 100644 --- a/packages/next/server/app-render.tsx +++ b/packages/next/server/app-render.tsx @@ -54,7 +54,7 @@ function preloadComponent(Component: any, props: any) { const prev = console.error // Hide invalid hook call warning when calling component console.error = function (msg) { - if (msg.startsWith('Invalid hook call..')) { + if (msg.startsWith('Warning: Invalid hook call.')) { // ignore } else { // @ts-expect-error argument is defined diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index f5424ec18bd08d3..912486fcd26db7b 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -136,8 +136,15 @@ describe('app dir', () => { if (!(global as any).isNextDeploy) { it('should serve /index as separate page', async () => { + const stderr = [] + next.on('stderr', (err) => { + stderr.push(err) + }) const html = await renderViaHTTP(next.url, '/dashboard/index') expect(html).toContain('hello from app/dashboard/index') + expect(stderr.some((err) => err.includes('Invalid hook call'))).toBe( + false + ) }) it('should handle next/dynamic correctly', async () => {