mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make sure dynamicIds are added when using function as importer (#5308)
This commit is contained in:
parent
f0f8229009
commit
1c328a8450
7
build/babel/plugins/react-loadable-plugin.js
vendored
7
build/babel/plugins/react-loadable-plugin.js
vendored
|
@ -62,15 +62,16 @@ export default function ({ types: t, template }) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].isCallExpression()) {
|
if (args[0].isObjectExpression()) {
|
||||||
|
options = args[0]
|
||||||
|
} else {
|
||||||
if (!args[1]) {
|
if (!args[1]) {
|
||||||
callExpression.pushContainer('arguments', t.objectExpression([]))
|
callExpression.pushContainer('arguments', t.objectExpression([]))
|
||||||
}
|
}
|
||||||
|
// This is needed as the code is modified above
|
||||||
args = callExpression.get('arguments')
|
args = callExpression.get('arguments')
|
||||||
loader = args[0]
|
loader = args[0]
|
||||||
options = args[1]
|
options = args[1]
|
||||||
} else {
|
|
||||||
options = args[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.isObjectExpression()) return
|
if (!options.isObjectExpression()) return
|
||||||
|
|
|
@ -12,11 +12,15 @@ export default (context, render) => {
|
||||||
describe('default behavior', () => {
|
describe('default behavior', () => {
|
||||||
it('should render dynamic import components', async () => {
|
it('should render dynamic import components', async () => {
|
||||||
const $ = await get$('/dynamic/ssr')
|
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/)
|
expect($('body').text()).toMatch(/Hello World 1/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should render dynamic import components using a function as first parameter', async () => {
|
it('should render dynamic import components using a function as first parameter', async () => {
|
||||||
const $ = await get$('/dynamic/function')
|
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/)
|
expect($('body').text()).toMatch(/Hello World 1/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -52,6 +56,7 @@ export default (context, render) => {
|
||||||
describe('ssr:false option', () => {
|
describe('ssr:false option', () => {
|
||||||
it('Should render loading on the server side', async () => {
|
it('Should render loading on the server side', async () => {
|
||||||
const $ = await get$('/dynamic/no-ssr')
|
const $ = await get$('/dynamic/no-ssr')
|
||||||
|
expect($('body').html()).not.toContain('"dynamicIds"')
|
||||||
expect($('p').text()).toBe('loading...')
|
expect($('p').text()).toBe('loading...')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue