mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make dynamic import spec compliant. (#2612)
* Make dynamic import spec compliant. Now we simply return the whole module incl. default field In 'next/dynamic' we pick the default field if there is. Since modules with default is mostly used next/dynamic, for the enduser, this change has no effect. * Rename module into m Using module could be confusing.
This commit is contained in:
parent
89d4e0af4a
commit
2f7e459210
|
@ -54,7 +54,8 @@ export default function dynamicComponent (p, o) {
|
|||
}
|
||||
|
||||
loadComponent () {
|
||||
promise.then((AsyncComponent) => {
|
||||
promise.then((m) => {
|
||||
const AsyncComponent = m.default || m
|
||||
// Set a readable displayName for the wrapper component
|
||||
const asyncCompName = getDisplayName(AsyncComponent)
|
||||
if (asyncCompName) {
|
||||
|
@ -65,7 +66,7 @@ export default function dynamicComponent (p, o) {
|
|||
this.setState({ AsyncComponent })
|
||||
} else {
|
||||
if (this.isServer) {
|
||||
registerChunk(AsyncComponent.__webpackChunkName)
|
||||
registerChunk(m.__webpackChunkName)
|
||||
}
|
||||
this.state.AsyncComponent = AsyncComponent
|
||||
}
|
||||
|
@ -100,9 +101,10 @@ export default function dynamicComponent (p, o) {
|
|||
|
||||
const loadModule = (name) => {
|
||||
const promise = modulePromiseMap[name]
|
||||
promise.then((Component) => {
|
||||
promise.then((m) => {
|
||||
const Component = m.default || m
|
||||
if (this.isServer) {
|
||||
registerChunk(Component.__webpackChunkName)
|
||||
registerChunk(m.__webpackChunkName)
|
||||
}
|
||||
moduleMap[name] = Component
|
||||
remainingPromises--
|
||||
|
|
|
@ -13,7 +13,6 @@ const buildImport = (args) => (template(`
|
|||
eval('require.ensure = function (deps, callback) { callback(require) }')
|
||||
require.ensure([], (require) => {
|
||||
let m = require(SOURCE)
|
||||
m = m.default || m
|
||||
m.__webpackChunkName = '${args.name}.js'
|
||||
resolve(m);
|
||||
}, 'chunks/${args.name}.js');
|
||||
|
@ -23,13 +22,12 @@ const buildImport = (args) => (template(`
|
|||
const weakId = require.resolveWeak(SOURCE)
|
||||
try {
|
||||
const weakModule = __webpack_require__(weakId)
|
||||
return resolve(weakModule.default || weakModule)
|
||||
return resolve(weakModule)
|
||||
} catch (err) {}
|
||||
|
||||
require.ensure([], (require) => {
|
||||
try {
|
||||
let m = require(SOURCE)
|
||||
m = m.default || m
|
||||
resolve(m)
|
||||
} catch(error) {
|
||||
reject(error)
|
||||
|
|
Loading…
Reference in a new issue