1
0
Fork 0
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:
Arunoda Susiripala 2017-07-20 23:21:04 +05:30 committed by GitHub
parent 89d4e0af4a
commit 2f7e459210
2 changed files with 7 additions and 7 deletions

View file

@ -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--

View file

@ -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)