From 1c328a84508afad67612b00814552acc1df27152 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 27 Sep 2018 16:40:54 +0200 Subject: [PATCH] Make sure dynamicIds are added when using function as importer (#5308) --- build/babel/plugins/react-loadable-plugin.js | 7 ++++--- test/integration/basic/test/dynamic.js | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/build/babel/plugins/react-loadable-plugin.js b/build/babel/plugins/react-loadable-plugin.js index 100e2e33..72974ed4 100644 --- a/build/babel/plugins/react-loadable-plugin.js +++ b/build/babel/plugins/react-loadable-plugin.js @@ -62,15 +62,16 @@ export default function ({ types: t, template }) { return } - if (args[0].isCallExpression()) { + if (args[0].isObjectExpression()) { + options = args[0] + } else { if (!args[1]) { callExpression.pushContainer('arguments', t.objectExpression([])) } + // This is needed as the code is modified above args = callExpression.get('arguments') loader = args[0] options = args[1] - } else { - options = args[0] } if (!options.isObjectExpression()) return diff --git a/test/integration/basic/test/dynamic.js b/test/integration/basic/test/dynamic.js index 48f94e85..8f65ebbf 100644 --- a/test/integration/basic/test/dynamic.js +++ b/test/integration/basic/test/dynamic.js @@ -12,11 +12,15 @@ export default (context, render) => { describe('default behavior', () => { it('should render dynamic import components', async () => { const $ = await get$('/dynamic/ssr') + // Make sure the client side knows it has to wait for the bundle + expect($('body').html()).toContain('"dynamicIds":["./components/hello1.js"]') expect($('body').text()).toMatch(/Hello World 1/) }) it('should render dynamic import components using a function as first parameter', async () => { const $ = await get$('/dynamic/function') + // Make sure the client side knows it has to wait for the bundle + expect($('body').html()).toContain('"dynamicIds":["./components/hello1.js"]') expect($('body').text()).toMatch(/Hello World 1/) }) @@ -52,6 +56,7 @@ export default (context, render) => { describe('ssr:false option', () => { it('Should render loading on the server side', async () => { const $ = await get$('/dynamic/no-ssr') + expect($('body').html()).not.toContain('"dynamicIds"') expect($('p').text()).toBe('loading...') })