From 6236b7d6857000b964f6101c092800080264d3fb Mon Sep 17 00:00:00 2001 From: Vsevolod Rodionov Date: Thu, 28 Sep 2017 17:31:22 +0300 Subject: [PATCH 1/2] fixing #2898 --- lib/dynamic.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/dynamic.js b/lib/dynamic.js index 939e1114befa7..dbe30c6189a8e 100644 --- a/lib/dynamic.js +++ b/lib/dynamic.js @@ -71,6 +71,13 @@ export default function dynamicComponent (p, o) { this.state.AsyncComponent = AsyncComponent } }) + .catch( + this.ssr + ? undefined + : (error) => { + window.next.renderError(error) + } + ) } loadBundle (props) { From 01bc8fa3248b238cae42305dd2f871a430284c96 Mon Sep 17 00:00:00 2001 From: jabher Date: Thu, 12 Oct 2017 11:56:36 +0300 Subject: [PATCH 2/2] tests wip --- .idea/codeStyleSettings.xml | 30 ++++++++++++++++ .../basic/components/crashing-in-component.js | 3 ++ test/integration/basic/components/crashing.js | 1 + .../dynamic/no-ssr-crashing-in-component.js | 5 +++ .../basic/pages/dynamic/no-ssr-crashing.js | 5 +++ .../dynamic/ssr-crashing-in-component.js | 5 +++ .../basic/pages/dynamic/ssr-crashing.js | 5 +++ test/integration/basic/test/dynamic.js | 36 +++++++++++++++++++ 8 files changed, 90 insertions(+) create mode 100644 .idea/codeStyleSettings.xml create mode 100644 test/integration/basic/components/crashing-in-component.js create mode 100644 test/integration/basic/components/crashing.js create mode 100644 test/integration/basic/pages/dynamic/no-ssr-crashing-in-component.js create mode 100644 test/integration/basic/pages/dynamic/no-ssr-crashing.js create mode 100644 test/integration/basic/pages/dynamic/ssr-crashing-in-component.js create mode 100644 test/integration/basic/pages/dynamic/ssr-crashing.js diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000000000..ba8dafde23ec3 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,30 @@ + + + + + + \ No newline at end of file diff --git a/test/integration/basic/components/crashing-in-component.js b/test/integration/basic/components/crashing-in-component.js new file mode 100644 index 0000000000000..ebc0ec0489d4a --- /dev/null +++ b/test/integration/basic/components/crashing-in-component.js @@ -0,0 +1,3 @@ +export default () => { + throw new Error('intentionally crashed') +} diff --git a/test/integration/basic/components/crashing.js b/test/integration/basic/components/crashing.js new file mode 100644 index 0000000000000..6126ea92b4b36 --- /dev/null +++ b/test/integration/basic/components/crashing.js @@ -0,0 +1 @@ +throw new Error('intentionally crashed') diff --git a/test/integration/basic/pages/dynamic/no-ssr-crashing-in-component.js b/test/integration/basic/pages/dynamic/no-ssr-crashing-in-component.js new file mode 100644 index 0000000000000..8046271e538a4 --- /dev/null +++ b/test/integration/basic/pages/dynamic/no-ssr-crashing-in-component.js @@ -0,0 +1,5 @@ +import dynamic from 'next/dynamic' + +const Error = dynamic(import('../../components/crashing-in-component'), { ssr: false }) + +export default Error diff --git a/test/integration/basic/pages/dynamic/no-ssr-crashing.js b/test/integration/basic/pages/dynamic/no-ssr-crashing.js new file mode 100644 index 0000000000000..661cfbed94b18 --- /dev/null +++ b/test/integration/basic/pages/dynamic/no-ssr-crashing.js @@ -0,0 +1,5 @@ +import dynamic from 'next/dynamic' + +const Error = dynamic(import('../../components/crashing'), { ssr: false }) + +export default Error diff --git a/test/integration/basic/pages/dynamic/ssr-crashing-in-component.js b/test/integration/basic/pages/dynamic/ssr-crashing-in-component.js new file mode 100644 index 0000000000000..f1b2ed78010af --- /dev/null +++ b/test/integration/basic/pages/dynamic/ssr-crashing-in-component.js @@ -0,0 +1,5 @@ +import dynamic from 'next/dynamic' + +const Error = dynamic(import('../../components/crashing-in-component')) + +export default Error diff --git a/test/integration/basic/pages/dynamic/ssr-crashing.js b/test/integration/basic/pages/dynamic/ssr-crashing.js new file mode 100644 index 0000000000000..a1dd75ded0705 --- /dev/null +++ b/test/integration/basic/pages/dynamic/ssr-crashing.js @@ -0,0 +1,5 @@ +import dynamic from 'next/dynamic' + +const Error = dynamic(import('../../components/crashing')) + +export default Error diff --git a/test/integration/basic/test/dynamic.js b/test/integration/basic/test/dynamic.js index 1744e4a1c8265..feb817ba9757b 100644 --- a/test/integration/basic/test/dynamic.js +++ b/test/integration/basic/test/dynamic.js @@ -16,6 +16,16 @@ export default (context, render) => { expect($('p').text()).toBe('Hello World 1') }) + it('should render dynamic import components crash if error was thrown in module', async () => { + const $ = await get$('/dynamic/ssr-crashing') + expect($('#__next-error').text()).toBe(/intentionally crashed/) + }) + + it('should render dynamic import components crash if error was thrown in component render', async () => { + const $ = await get$('/dynamic/ssr-crashing-in-component') + expect($('#__next-error').text()).toMatch(/intentionally crashed/) + }) + it('should stop render dynmaic import components', async () => { const $ = await get$('/dynamic/no-ssr') expect($('p').text()).toBe('loading...') @@ -57,6 +67,32 @@ export default (context, render) => { browser.close() }) + it('should render the thrown error on client side if error was thrown in module', async () => { + const browser = await webdriver(context.appPort, '/dynamic/no-ssr-crashing') + + while (true) { + const bodyText = await browser + .elementByCss('body').text() + if (/intentionally crashed/.test(bodyText)) break + await waitFor(1000) + } + + browser.close() + }) + + it('should render the thrown error on client side if error was thrown in component render', async () => { + const browser = await webdriver(context.appPort, '/dynamic/no-ssr-crashing-in-component') + + while (true) { + const bodyText = await browser + .elementByCss('body').text() + if (/intentionally crashed/.test(bodyText)) break + await waitFor(1000) + } + + browser.close() + }) + it('should render even there are no physical chunk exists', async () => { const browser = await webdriver(context.appPort, '/dynamic/no-chunk')