Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
ee220730
Unverified
Commit
ee220730
authored
Dec 14, 2021
by
Tobias Koppers
Committed by
GitHub
Dec 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes to allow lazy compilation for import() (#32441)
parent
67545bd6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
42 changed files
with
687 additions
and
372 deletions
+687
-372
.eslintignore
.eslintignore
+1
-0
.prettierignore
.prettierignore
+1
-0
lib.rs
packages/next-swc/crates/core/src/lib.rs
+9
-1
next_dynamic.rs
packages/next-swc/crates/core/src/next_dynamic.rs
+241
-217
errors.rs
packages/next-swc/crates/core/tests/errors.rs
+2
-0
fixture.rs
packages/next-swc/crates/core/tests/fixture.rs
+18
-2
output-dev.js
...sts/fixture/next-dynamic/duplicated-imports/output-dev.js
+12
-0
output-prod.js
...ts/fixture/next-dynamic/duplicated-imports/output-prod.js
+0
-2
output-dev.js
.../fixture/next-dynamic/member-with-same-name/output-dev.js
+8
-0
output-prod.js
...fixture/next-dynamic/member-with-same-name/output-prod.js
+0
-1
output-dev.js
.../core/tests/fixture/next-dynamic/no-options/output-dev.js
+6
-0
output-prod.js
...core/tests/fixture/next-dynamic/no-options/output-prod.js
+0
-1
output-dev.js
...ore/tests/fixture/next-dynamic/with-options/output-dev.js
+10
-0
output-prod.js
...re/tests/fixture/next-dynamic/with-options/output-prod.js
+0
-4
output-dev.js
...e/tests/fixture/next-dynamic/wrapped-import/output-dev.js
+12
-0
output-prod.js
.../tests/fixture/next-dynamic/wrapped-import/output-prod.js
+0
-4
full.rs
packages/next-swc/crates/core/tests/full.rs
+1
-0
react-loadable-plugin.ts
packages/next/build/babel/plugins/react-loadable-plugin.ts
+28
-22
options.js
packages/next/build/swc/options.js
+2
-0
webpack-config.ts
packages/next/build/webpack-config.ts
+16
-0
react-loadable-plugin.ts
packages/next/build/webpack/plugins/react-loadable-plugin.ts
+12
-3
lazy-compilation-node.js
...es/next/bundles/webpack/packages/lazy-compilation-node.js
+40
-0
lazy-compilation-web.js
...ges/next/bundles/webpack/packages/lazy-compilation-web.js
+74
-0
lazy-compilation-node.js
packages/next/compiled/webpack/lazy-compilation-node.js
+2
-68
lazy-compilation-web.js
packages/next/compiled/webpack/lazy-compilation-web.js
+1
-18
loadable.js
packages/next/shared/lib/loadable.js
+10
-14
taskfile.js
packages/next/taskfile.js
+1
-1
check-pre-compiled.bat
scripts/check-pre-compiled.bat
+8
-0
check-pre-compiled.sh
scripts/check-pre-compiled.sh
+2
-0
next-dynamic.test.ts
test/development/basic-basepath/next-dynamic.test.ts
+2
-2
next-dynamic.test.ts
test/development/basic/next-dynamic.test.ts
+2
-2
index.test.js
test/integration/app-document-add-hmr/test/index.test.js
+14
-9
.babelrc
test/integration/next-dynamic-lazy-compilation/.babelrc
+3
-0
index.js
...integration/next-dynamic-lazy-compilation/apples/index.js
+1
-0
four.js
...egration/next-dynamic-lazy-compilation/components/four.js
+3
-0
one.js
...tegration/next-dynamic-lazy-compilation/components/one.js
+6
-0
three.js
...gration/next-dynamic-lazy-compilation/components/three.js
+3
-0
two.js
...tegration/next-dynamic-lazy-compilation/components/two.js
+6
-0
next.config.js
.../integration/next-dynamic-lazy-compilation/next.config.js
+8
-0
index.js
.../integration/next-dynamic-lazy-compilation/pages/index.js
+48
-0
index.test.js
...egration/next-dynamic-lazy-compilation/test/index.test.js
+73
-0
next-babel-loader-prod.test.ts
test/unit/next-babel-loader-prod.test.ts
+1
-1
No files found.
.eslintignore
View file @
ee220730
...
@@ -12,6 +12,7 @@ examples/with-jest/**
...
@@ -12,6 +12,7 @@ examples/with-jest/**
examples/with-mobx-state-tree/**
examples/with-mobx-state-tree/**
examples/with-mobx/**
examples/with-mobx/**
packages/next/bundles/webpack/packages/*.runtime.js
packages/next/bundles/webpack/packages/*.runtime.js
packages/next/bundles/webpack/packages/lazy-compilation-*.js
packages/next/compiled/**/*
packages/next/compiled/**/*
packages/react-refresh-utils/**/*.js
packages/react-refresh-utils/**/*.js
packages/react-dev-overlay/lib/**
packages/react-dev-overlay/lib/**
...
...
.prettierignore
View file @
ee220730
...
@@ -3,6 +3,7 @@ node_modules
...
@@ -3,6 +3,7 @@ node_modules
**/_next/**
**/_next/**
**/dist/**
**/dist/**
packages/next/bundles/webpack/packages/*.runtime.js
packages/next/bundles/webpack/packages/*.runtime.js
packages/next/bundles/webpack/packages/lazy-compilation-*.js
packages/next/compiled/**
packages/next/compiled/**
packages/react-refresh-utils/**/*.js
packages/react-refresh-utils/**/*.js
packages/react-refresh-utils/**/*.d.ts
packages/react-refresh-utils/**/*.d.ts
...
...
packages/next-swc/crates/core/src/lib.rs
View file @
ee220730
...
@@ -79,6 +79,9 @@ pub struct TransformOptions {
...
@@ -79,6 +79,9 @@ pub struct TransformOptions {
#[serde(default)]
#[serde(default)]
pub
is_development
:
bool
,
pub
is_development
:
bool
,
#[serde(default)]
pub
is_server
:
bool
,
#[serde(default)]
#[serde(default)]
pub
styled_components
:
Option
<
styled_components
::
Config
>
,
pub
styled_components
:
Option
<
styled_components
::
Config
>
,
...
@@ -113,7 +116,12 @@ pub fn custom_before_pass(file: Arc<SourceFile>, opts: &TransformOptions) -> imp
...
@@ -113,7 +116,12 @@ pub fn custom_before_pass(file: Arc<SourceFile>, opts: &TransformOptions) -> imp
},
},
Optional
::
new
(
next_ssg
::
next_ssg
(),
!
opts
.disable_next_ssg
),
Optional
::
new
(
next_ssg
::
next_ssg
(),
!
opts
.disable_next_ssg
),
amp_attributes
::
amp_attributes
(),
amp_attributes
::
amp_attributes
(),
next_dynamic
::
next_dynamic
(
file
.name
.clone
(),
opts
.pages_dir
.clone
()),
next_dynamic
::
next_dynamic
(
opts
.is_development
,
opts
.is_server
,
file
.name
.clone
(),
opts
.pages_dir
.clone
()
),
Optional
::
new
(
Optional
::
new
(
page_config
::
page_config
(
opts
.is_development
,
opts
.is_page_file
),
page_config
::
page_config
(
opts
.is_development
,
opts
.is_page_file
),
!
opts
.disable_page_config
!
opts
.disable_page_config
...
...
packages/next-swc/crates/core/src/next_dynamic.rs
View file @
ee220730
This diff is collapsed.
Click to expand it.
packages/next-swc/crates/core/tests/errors.rs
View file @
ee220730
...
@@ -32,6 +32,8 @@ fn next_dynamic_errors(input: PathBuf) {
...
@@ -32,6 +32,8 @@ fn next_dynamic_errors(input: PathBuf) {
syntax
(),
syntax
(),
&
|
_tr
|
{
&
|
_tr
|
{
next_dynamic
(
next_dynamic
(
true
,
false
,
FileName
::
Real
(
PathBuf
::
from
(
"/some-project/src/some-file.js"
)),
FileName
::
Real
(
PathBuf
::
from
(
"/some-project/src/some-file.js"
)),
Some
(
"/some-project/src"
.into
()),
Some
(
"/some-project/src"
.into
()),
)
)
...
...
packages/next-swc/crates/core/tests/fixture.rs
View file @
ee220730
...
@@ -33,17 +33,33 @@ fn amp_attributes_fixture(input: PathBuf) {
...
@@ -33,17 +33,33 @@ fn amp_attributes_fixture(input: PathBuf) {
#[fixture(
"tests/fixture/next-dynamic/**/input.js"
)]
#[fixture(
"tests/fixture/next-dynamic/**/input.js"
)]
fn
next_dynamic_fixture
(
input
:
PathBuf
)
{
fn
next_dynamic_fixture
(
input
:
PathBuf
)
{
let
output
=
input
.parent
()
.unwrap
()
.join
(
"output.js"
);
let
output_dev
=
input
.parent
()
.unwrap
()
.join
(
"output-dev.js"
);
let
output_prod
=
input
.parent
()
.unwrap
()
.join
(
"output-prod.js"
);
test_fixture
(
test_fixture
(
syntax
(),
syntax
(),
&
|
_tr
|
{
&
|
_tr
|
{
next_dynamic
(
next_dynamic
(
true
,
false
,
FileName
::
Real
(
PathBuf
::
from
(
"/some-project/src/some-file.js"
)),
FileName
::
Real
(
PathBuf
::
from
(
"/some-project/src/some-file.js"
)),
Some
(
"/some-project/src"
.into
()),
Some
(
"/some-project/src"
.into
()),
)
)
},
},
&
input
,
&
input
,
&
output
,
&
output_dev
,
);
test_fixture
(
syntax
(),
&
|
_tr
|
{
next_dynamic
(
false
,
false
,
FileName
::
Real
(
PathBuf
::
from
(
"/some-project/src/some-file.js"
)),
Some
(
"/some-project/src"
.into
()),
)
},
&
input
,
&
output_prod
,
);
);
}
}
...
...
packages/next-swc/crates/core/tests/fixture/next-dynamic/duplicated-imports/output-dev.js
0 → 100644
View file @
ee220730
import
dynamic1
from
'next/dynamic'
import
dynamic2
from
'next/dynamic'
const
DynamicComponent1
=
dynamic1
(()
=>
import
(
'../components/hello1'
),
{
loadableGenerated
:
{
modules
:
[
'some-file.js -> '
+
'../components/hello1'
],
},
})
const
DynamicComponent2
=
dynamic2
(()
=>
import
(
'../components/hello2'
),
{
loadableGenerated
:
{
modules
:
[
'some-file.js -> '
+
'../components/hello2'
],
},
})
packages/next-swc/crates/core/tests/fixture/next-dynamic/duplicated-imports/output.js
→
packages/next-swc/crates/core/tests/fixture/next-dynamic/duplicated-imports/output
-prod
.js
View file @
ee220730
...
@@ -3,12 +3,10 @@ import dynamic2 from 'next/dynamic'
...
@@ -3,12 +3,10 @@ import dynamic2 from 'next/dynamic'
const
DynamicComponent1
=
dynamic1
(()
=>
import
(
'../components/hello1'
),
{
const
DynamicComponent1
=
dynamic1
(()
=>
import
(
'../components/hello1'
),
{
loadableGenerated
:
{
loadableGenerated
:
{
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello1'
)],
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello1'
)],
modules
:
[
'some-file.js -> '
+
'../components/hello1'
],
},
},
})
})
const
DynamicComponent2
=
dynamic2
(()
=>
import
(
'../components/hello2'
),
{
const
DynamicComponent2
=
dynamic2
(()
=>
import
(
'../components/hello2'
),
{
loadableGenerated
:
{
loadableGenerated
:
{
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello2'
)],
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello2'
)],
modules
:
[
'some-file.js -> '
+
'../components/hello2'
],
},
},
})
})
packages/next-swc/crates/core/tests/fixture/next-dynamic/member-with-same-name/output-dev.js
0 → 100644
View file @
ee220730
import
dynamic
from
'next/dynamic'
import
somethingElse
from
'something-else'
const
DynamicComponent
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
loadableGenerated
:
{
modules
:
[
'some-file.js -> '
+
'../components/hello'
],
},
})
somethingElse
.
dynamic
(
'should not be transformed'
)
packages/next-swc/crates/core/tests/fixture/next-dynamic/member-with-same-name/output.js
→
packages/next-swc/crates/core/tests/fixture/next-dynamic/member-with-same-name/output
-prod
.js
View file @
ee220730
...
@@ -3,7 +3,6 @@ import somethingElse from 'something-else'
...
@@ -3,7 +3,6 @@ import somethingElse from 'something-else'
const
DynamicComponent
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
const
DynamicComponent
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
loadableGenerated
:
{
loadableGenerated
:
{
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello'
)],
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello'
)],
modules
:
[
'some-file.js -> '
+
'../components/hello'
],
},
},
})
})
somethingElse
.
dynamic
(
'should not be transformed'
)
somethingElse
.
dynamic
(
'should not be transformed'
)
packages/next-swc/crates/core/tests/fixture/next-dynamic/no-options/output-dev.js
0 → 100644
View file @
ee220730
import
dynamic
from
'next/dynamic'
const
DynamicComponent
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
loadableGenerated
:
{
modules
:
[
'some-file.js -> '
+
'../components/hello'
],
},
})
packages/next-swc/crates/core/tests/fixture/next-dynamic/no-options/output.js
→
packages/next-swc/crates/core/tests/fixture/next-dynamic/no-options/output
-prod
.js
View file @
ee220730
...
@@ -2,6 +2,5 @@ import dynamic from 'next/dynamic'
...
@@ -2,6 +2,5 @@ import dynamic from 'next/dynamic'
const
DynamicComponent
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
const
DynamicComponent
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
loadableGenerated
:
{
loadableGenerated
:
{
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello'
)],
webpack
:
()
=>
[
require
.
resolveWeak
(
'../components/hello'
)],
modules
:
[
'some-file.js -> '
+
'../components/hello'
],
},
},
})
})
packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-dev.js
0 → 100644
View file @
ee220730
import
dynamic
from
"next/dynamic"
;
const
DynamicComponentWithCustomLoading
=
dynamic
(()
=>
import
(
"../components/hello"
)
,
{
loadableGenerated
:
{
modules
:
[
"some-file.js -> "
+
"../components/hello"
]
},
loading
:
()
=><
p
>
...
<
/p
>
});
packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output.js
→
packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output
-prod
.js
View file @
ee220730
...
@@ -5,10 +5,6 @@ const DynamicComponentWithCustomLoading = dynamic(()=>import("../components/hell
...
@@ -5,10 +5,6 @@ const DynamicComponentWithCustomLoading = dynamic(()=>import("../components/hell
webpack
:
()
=>
[
webpack
:
()
=>
[
require
.
resolveWeak
(
"../components/hello"
)
require
.
resolveWeak
(
"../components/hello"
)
]
]
,
modules
:
[
"some-file.js -> "
+
"../components/hello"
]
},
},
loading
:
()
=><
p
>
...
<
/p
>
loading
:
()
=><
p
>
...
<
/p
>
});
});
packages/next-swc/crates/core/tests/fixture/next-dynamic/wrapped-import/output-dev.js
0 → 100644
View file @
ee220730
import
dynamic
from
"next/dynamic"
;
const
DynamicComponent
=
dynamic
(()
=>
handleImport
(
import
(
"./components/hello"
))
,
{
loadableGenerated
:
{
modules
:
[
"some-file.js -> "
+
"./components/hello"
]
},
loading
:
()
=>
null
,
ssr
:
false
});
\ No newline at end of file
packages/next-swc/crates/core/tests/fixture/next-dynamic/wrapped-import/output.js
→
packages/next-swc/crates/core/tests/fixture/next-dynamic/wrapped-import/output
-prod
.js
View file @
ee220730
...
@@ -5,10 +5,6 @@ const DynamicComponent = dynamic(()=>handleImport(import("./components/hello"))
...
@@ -5,10 +5,6 @@ const DynamicComponent = dynamic(()=>handleImport(import("./components/hello"))
webpack
:
()
=>
[
webpack
:
()
=>
[
require
.
resolveWeak
(
"./components/hello"
)
require
.
resolveWeak
(
"./components/hello"
)
]
]
,
modules
:
[
"some-file.js -> "
+
"./components/hello"
]
},
},
loading
:
()
=>
null
loading
:
()
=>
null
,
,
...
...
packages/next-swc/crates/core/tests/full.rs
View file @
ee220730
...
@@ -55,6 +55,7 @@ fn test(input: &Path, minify: bool) {
...
@@ -55,6 +55,7 @@ fn test(input: &Path, minify: bool) {
pages_dir
:
None
,
pages_dir
:
None
,
is_page_file
:
false
,
is_page_file
:
false
,
is_development
:
true
,
is_development
:
true
,
is_server
:
false
,
styled_components
:
Some
(
assert_json
(
"{}"
)),
styled_components
:
Some
(
assert_json
(
"{}"
)),
remove_console
:
None
,
remove_console
:
None
,
react_remove_properties
:
None
,
react_remove_properties
:
None
,
...
...
packages/next/build/babel/plugins/react-loadable-plugin.ts
View file @
ee220730
...
@@ -168,7 +168,16 @@ export default function ({
...
@@ -168,7 +168,16 @@ export default function ({
options
.
node
.
properties
.
push
(
options
.
node
.
properties
.
push
(
t
.
objectProperty
(
t
.
objectProperty
(
t
.
identifier
(
'loadableGenerated'
),
t
.
identifier
(
'loadableGenerated'
),
t
.
objectExpression
([
t
.
objectExpression
(
state
.
file
.
opts
.
caller
?.
isDev
||
state
.
file
.
opts
.
caller
?.
isServer
?
[
t
.
objectProperty
(
t
.
identifier
(
'modules'
),
t
.
arrayExpression
(
dynamicKeys
)
),
]
:
[
t
.
objectProperty
(
t
.
objectProperty
(
t
.
identifier
(
'webpack'
),
t
.
identifier
(
'webpack'
),
t
.
arrowFunctionExpression
(
t
.
arrowFunctionExpression
(
...
@@ -186,11 +195,8 @@ export default function ({
...
@@ -186,11 +195,8 @@ export default function ({
)
)
)
)
),
),
t
.
objectProperty
(
]
t
.
identifier
(
'modules'
),
)
t
.
arrayExpression
(
dynamicKeys
)
),
])
)
)
)
)
...
...
packages/next/build/swc/options.js
View file @
ee220730
...
@@ -141,6 +141,7 @@ export function getLoaderSWCOptions({
...
@@ -141,6 +141,7 @@ export function getLoaderSWCOptions({
disableNextSsg
:
true
,
disableNextSsg
:
true
,
disablePageConfig
:
true
,
disablePageConfig
:
true
,
isDevelopment
:
development
,
isDevelopment
:
development
,
isServer
,
pagesDir
,
pagesDir
,
isPageFile
,
isPageFile
,
env
:
{
env
:
{
...
@@ -165,6 +166,7 @@ export function getLoaderSWCOptions({
...
@@ -165,6 +166,7 @@ export function getLoaderSWCOptions({
:
{}),
:
{}),
disableNextSsg
:
!
isPageFile
,
disableNextSsg
:
!
isPageFile
,
isDevelopment
:
development
,
isDevelopment
:
development
,
isServer
,
pagesDir
,
pagesDir
,
isPageFile
,
isPageFile
,
}
}
...
...
packages/next/build/webpack-config.ts
View file @
ee220730
...
@@ -1402,6 +1402,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1402,6 +1402,7 @@ export default async function getBaseWebpackConfig(
runtimeAsset
:
hasConcurrentFeatures
runtimeAsset
:
hasConcurrentFeatures
?
`server/
${
MIDDLEWARE_REACT_LOADABLE_MANIFEST
}
.js`
?
`server/
${
MIDDLEWARE_REACT_LOADABLE_MANIFEST
}
.js`
:
undefined
,
:
undefined
,
dev
,
}),
}),
targetWeb
&&
new
DropClientPage
(),
targetWeb
&&
new
DropClientPage
(),
config
.
outputFileTracing
&&
config
.
outputFileTracing
&&
...
@@ -1733,6 +1734,21 @@ export default async function getBaseWebpackConfig(
...
@@ -1733,6 +1734,21 @@ export default async function getBaseWebpackConfig(
devtoolRevertWarning
(
originalDevtool
)
devtoolRevertWarning
(
originalDevtool
)
}
}
// eslint-disable-next-line no-shadow
const
webpack5Config
=
webpackConfig
as
webpack5
.
Configuration
// disable lazy compilation of entries as next.js has it's own method here
if
(
webpack5Config
.
experiments
?.
lazyCompilation
===
true
)
{
webpack5Config
.
experiments
.
lazyCompilation
=
{
entries
:
false
,
}
}
else
if
(
typeof
webpack5Config
.
experiments
?.
lazyCompilation
===
'object'
&&
webpack5Config
.
experiments
.
lazyCompilation
.
entries
!==
false
)
{
webpack5Config
.
experiments
.
lazyCompilation
.
entries
=
false
}
if
(
typeof
(
webpackConfig
as
any
).
then
===
'function'
)
{
if
(
typeof
(
webpackConfig
as
any
).
then
===
'function'
)
{
console
.
warn
(
console
.
warn
(
'> Promise returned in next config. https://nextjs.org/docs/messages/promise-in-next-config'
'> Promise returned in next config. https://nextjs.org/docs/messages/promise-in-next-config'
...
...
packages/next/build/webpack/plugins/react-loadable-plugin.ts
View file @
ee220730
...
@@ -53,7 +53,8 @@ function getChunkGroupFromBlock(
...
@@ -53,7 +53,8 @@ function getChunkGroupFromBlock(
function
buildManifest
(
function
buildManifest
(
_compiler
:
webpack
.
Compiler
,
_compiler
:
webpack
.
Compiler
,
compilation
:
webpack
.
compilation
.
Compilation
,
compilation
:
webpack
.
compilation
.
Compilation
,
pagesDir
:
string
pagesDir
:
string
,
dev
:
boolean
)
{
)
{
let
manifest
:
{
[
k
:
string
]:
{
id
:
string
|
number
;
files
:
string
[]
}
}
=
{}
let
manifest
:
{
[
k
:
string
]:
{
id
:
string
|
number
;
files
:
string
[]
}
}
=
{}
...
@@ -125,7 +126,7 @@ function buildManifest(
...
@@ -125,7 +126,7 @@ function buildManifest(
// next/dynamic so they are loaded by the same technique
// next/dynamic so they are loaded by the same technique
// add the id and files to the manifest
// add the id and files to the manifest
const
id
=
getModuleId
(
compilation
,
module
)
const
id
=
dev
?
key
:
getModuleId
(
compilation
,
module
)
manifest
[
key
]
=
{
id
,
files
:
Array
.
from
(
files
)
}
manifest
[
key
]
=
{
id
,
files
:
Array
.
from
(
files
)
}
}
}
}
}
...
@@ -146,19 +147,27 @@ export class ReactLoadablePlugin {
...
@@ -146,19 +147,27 @@ export class ReactLoadablePlugin {
private
filename
:
string
private
filename
:
string
private
pagesDir
:
string
private
pagesDir
:
string
private
runtimeAsset
?:
string
private
runtimeAsset
?:
string
private
dev
:
boolean
constructor
(
opts
:
{
constructor
(
opts
:
{
filename
:
string
filename
:
string
pagesDir
:
string
pagesDir
:
string
runtimeAsset
?:
string
runtimeAsset
?:
string
dev
:
boolean
})
{
})
{
this
.
filename
=
opts
.
filename
this
.
filename
=
opts
.
filename
this
.
pagesDir
=
opts
.
pagesDir
this
.
pagesDir
=
opts
.
pagesDir
this
.
runtimeAsset
=
opts
.
runtimeAsset
this
.
runtimeAsset
=
opts
.
runtimeAsset
this
.
dev
=
opts
.
dev
}
}
createAssets
(
compiler
:
any
,
compilation
:
any
,
assets
:
any
)
{
createAssets
(
compiler
:
any
,
compilation
:
any
,
assets
:
any
)
{
const
manifest
=
buildManifest
(
compiler
,
compilation
,
this
.
pagesDir
)
const
manifest
=
buildManifest
(
compiler
,
compilation
,
this
.
pagesDir
,
this
.
dev
)
// @ts-ignore: TODO: remove when webpack 5 is stable
// @ts-ignore: TODO: remove when webpack 5 is stable
assets
[
this
.
filename
]
=
new
sources
.
RawSource
(
assets
[
this
.
filename
]
=
new
sources
.
RawSource
(
JSON
.
stringify
(
manifest
,
null
,
2
)
JSON
.
stringify
(
manifest
,
null
,
2
)
...
...
packages/next/bundles/webpack/packages/lazy-compilation-node.js
0 → 100644
View file @
ee220730
/* global __resourceQuery */
"use strict"
;
var
urlBase
=
decodeURIComponent
(
__resourceQuery
.
slice
(
1
));
exports
.
keepAlive
=
function
(
options
)
{
var
data
=
options
.
data
;
var
onError
=
options
.
onError
;
var
active
=
options
.
active
;
var
module
=
options
.
module
;
var
response
;
var
request
=
(
urlBase
.
startsWith
(
"https"
)
?
require
(
"https"
)
:
require
(
"http"
)
).
request
(
urlBase
+
data
,
{
agent
:
false
,
headers
:
{
accept
:
"text/event-stream"
}
},
function
(
res
)
{
response
=
res
;
response
.
on
(
"error"
,
errorHandler
);
if
(
!
active
&&
!
module
.
hot
)
{
console
.
log
(
"Hot Module Replacement is not enabled. Waiting for process restart..."
);
}
}
);
function
errorHandler
(
err
)
{
err
.
message
=
"Problem communicating active modules to the server: "
+
err
.
message
;
onError
(
err
);
}
request
.
on
(
"error"
,
errorHandler
);
request
.
end
();
return
function
()
{
response
.
destroy
();
};
};
packages/next/bundles/webpack/packages/lazy-compilation-web.js
0 → 100644
View file @
ee220730
/* global __resourceQuery */
"use strict"
;
if
(
typeof
EventSource
!==
"function"
)
{
throw
new
Error
(
"Environment doesn't support lazy compilation (requires EventSource)"
);
}
var
urlBase
=
decodeURIComponent
(
__resourceQuery
.
slice
(
1
));
var
activeEventSource
;
var
activeKeys
=
new
Map
();
var
errorHandlers
=
new
Set
();
var
updateEventSource
=
function
updateEventSource
()
{
if
(
activeEventSource
)
activeEventSource
.
close
();
if
(
activeKeys
.
size
)
{
activeEventSource
=
new
EventSource
(
urlBase
+
Array
.
from
(
activeKeys
.
keys
()).
join
(
"@"
)
);
activeEventSource
.
onerror
=
function
(
event
)
{
errorHandlers
.
forEach
(
function
(
onError
)
{
onError
(
new
Error
(
"Problem communicating active modules to the server: "
+
event
.
message
+
" "
+
event
.
filename
+
":"
+
event
.
lineno
+
":"
+
event
.
colno
+
" "
+
event
.
error
)
);
});
};
}
else
{
activeEventSource
=
undefined
;
}
};
exports
.
keepAlive
=
function
(
options
)
{
var
data
=
options
.
data
;
var
onError
=
options
.
onError
;
var
active
=
options
.
active
;
var
module
=
options
.
module
;
errorHandlers
.
add
(
onError
);
var
value
=
activeKeys
.
get
(
data
)
||
0
;
activeKeys
.
set
(
data
,
value
+
1
);
if
(
value
===
0
)
{
updateEventSource
();
}
if
(
!
active
&&
!
module
.
hot
)
{
console
.
log
(
"Hot Module Replacement is not enabled. Waiting for process restart..."
);
}
return
function
()
{
errorHandlers
.
delete
(
onError
);
setTimeout
(
function
()
{
var
value
=
activeKeys
.
get
(
data
);
if
(
value
===
1
)
{
activeKeys
.
delete
(
data
);
updateEventSource
();
}
else
{
activeKeys
.
set
(
data
,
value
-
1
);
}
},
1000
);
};
};
packages/next/compiled/webpack/lazy-compilation-node.js
View file @
ee220730
/******/
(
function
()
{
// webpackBootstrap
/******/
"use strict"
;
/******/
var
__webpack_modules__
=
({
/***/
685
:
/***/
(
function
(
module
)
{
module
.
exports
=
require
(
"http"
);
/***/
}),
/***/
687
:
/***/
(
function
(
module
)
{
module
.
exports
=
require
(
"https"
);
/***/
})
/******/
});
/************************************************************************/
/******/
// The module cache
/******/
var
__webpack_module_cache__
=
{};
/******/
/******/
// The require function
/******/
function
__nccwpck_require__
(
moduleId
)
{
/******/
// Check if module is in cache
/******/
var
cachedModule
=
__webpack_module_cache__
[
moduleId
];
/******/
if
(
cachedModule
!==
undefined
)
{
/******/
return
cachedModule
.
exports
;
/******/
}
/******/
// Create a new module (and put it into the cache)
/******/
var
module
=
__webpack_module_cache__
[
moduleId
]
=
{
/******/
// no module.id needed
/******/
// no module.loaded needed
/******/
exports
:
{}
/******/
};
/******/
/******/
// Execute the module function
/******/
var
threw
=
true
;
/******/
try
{
/******/
__webpack_modules__
[
moduleId
](
module
,
module
.
exports
,
__nccwpck_require__
);
/******/
threw
=
false
;
/******/
}
finally
{
/******/
if
(
threw
)
delete
__webpack_module_cache__
[
moduleId
];
/******/
}
/******/
/******/
// Return the exports of the module
/******/
return
module
.
exports
;
/******/
}
/******/
/************************************************************************/
/******/
/* webpack/runtime/compat */
/******/
/******/
if
(
typeof
__nccwpck_require__
!==
'undefined'
)
__nccwpck_require__
.
ab
=
__dirname
+
"/"
;
/******/
/************************************************************************/
var
__webpack_exports__
=
{};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
!
function
()
{
var
exports
=
__webpack_exports__
;
var
__resourceQuery
=
""
;
/* global __resourceQuery */
/* global __resourceQuery */
"use strict"
;
var
urlBase
=
decodeURIComponent
(
__resourceQuery
.
slice
(
1
));
var
urlBase
=
decodeURIComponent
(
__resourceQuery
.
slice
(
1
));
exports
.
keepAlive
=
function
(
options
)
{
exports
.
keepAlive
=
function
(
options
)
{
...
@@ -71,7 +10,7 @@ exports.keepAlive = function (options) {
...
@@ -71,7 +10,7 @@ exports.keepAlive = function (options) {
var
module
=
options
.
module
;
var
module
=
options
.
module
;
var
response
;
var
response
;
var
request
=
(
var
request
=
(
urlBase
.
startsWith
(
"https"
)
?
__nccwpck_require__
(
687
)
:
__nccwpck_require__
(
685
)
urlBase
.
startsWith
(
"https"
)
?
require
(
"https"
)
:
require
(
"http"
)
).
request
(
).
request
(
urlBase
+
data
,
urlBase
+
data
,
{
{
...
@@ -99,8 +38,3 @@ exports.keepAlive = function (options) {
...
@@ -99,8 +38,3 @@ exports.keepAlive = function (options) {
response
.
destroy
();
response
.
destroy
();
};
};
};
};
}();
module
.
exports
=
__webpack_exports__
;
/******/
})()
;
\ No newline at end of file
packages/next/compiled/webpack/lazy-compilation-web.js
View file @
ee220730
/******/
(
function
()
{
// webpackBootstrap
/******/
"use strict"
;
/******/
/* webpack/runtime/compat */
/******/
/******/
if
(
typeof
__nccwpck_require__
!==
'undefined'
)
__nccwpck_require__
.
ab
=
__dirname
+
"/"
;
/******/
/************************************************************************/
var
__webpack_exports__
=
{};
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
!
function
()
{
var
exports
=
__webpack_exports__
;
var
__resourceQuery
=
""
;
/* global __resourceQuery */
/* global __resourceQuery */
"use strict"
;
if
(
typeof
EventSource
!==
"function"
)
{
if
(
typeof
EventSource
!==
"function"
)
{
throw
new
Error
(
throw
new
Error
(
...
@@ -84,8 +72,3 @@ exports.keepAlive = function (options) {
...
@@ -84,8 +72,3 @@ exports.keepAlive = function (options) {
},
1000
);
},
1000
);
};
};
};
};
}();
module
.
exports
=
__webpack_exports__
;
/******/
})()
;
\ No newline at end of file
packages/next/shared/lib/loadable.js
View file @
ee220730
...
@@ -95,14 +95,9 @@ function createLoadableComponent(loadFn, options) {
...
@@ -95,14 +95,9 @@ function createLoadableComponent(loadFn, options) {
}
}
// Client only
// Client only
if
(
if
(
!
initialized
&&
typeof
window
!==
'undefined'
&&
!
opts
.
suspense
)
{
!
initialized
&&
const
moduleIds
=
opts
.
webpack
?
opts
.
webpack
()
:
opts
.
modules
typeof
window
!==
'undefined'
&&
if
(
moduleIds
)
{
typeof
opts
.
webpack
===
'function'
&&
typeof
require
.
resolveWeak
===
'function'
&&
!
opts
.
suspense
)
{
const
moduleIds
=
opts
.
webpack
()
READY_INITIALIZERS
.
push
((
ids
)
=>
{
READY_INITIALIZERS
.
push
((
ids
)
=>
{
for
(
const
moduleId
of
moduleIds
)
{
for
(
const
moduleId
of
moduleIds
)
{
if
(
ids
.
indexOf
(
moduleId
)
!==
-
1
)
{
if
(
ids
.
indexOf
(
moduleId
)
!==
-
1
)
{
...
@@ -111,6 +106,7 @@ function createLoadableComponent(loadFn, options) {
...
@@ -111,6 +106,7 @@ function createLoadableComponent(loadFn, options) {
}
}
})
})
}
}
}
function
LoadableImpl
(
props
,
ref
)
{
function
LoadableImpl
(
props
,
ref
)
{
init
()
init
()
...
...
packages/next/taskfile.js
View file @
ee220730
...
@@ -1007,7 +1007,6 @@ export async function ncc(task, opts) {
...
@@ -1007,7 +1007,6 @@ export async function ncc(task, opts) {
'ncc_unistore'
,
'ncc_unistore'
,
'ncc_web_vitals'
,
'ncc_web_vitals'
,
'ncc_webpack_bundle5'
,
'ncc_webpack_bundle5'
,
'ncc_webpack_bundle_packages'
,
'ncc_webpack_sources1'
,
'ncc_webpack_sources1'
,
'ncc_webpack_sources3'
,
'ncc_webpack_sources3'
,
'ncc_ws'
,
'ncc_ws'
,
...
@@ -1021,6 +1020,7 @@ export async function ncc(task, opts) {
...
@@ -1021,6 +1020,7 @@ export async function ncc(task, opts) {
],
],
opts
opts
)
)
await
task
.
parallel
([
'ncc_webpack_bundle_packages'
],
opts
)
await
task
.
parallel
([
'ncc_babel_bundle_packages'
],
opts
)
await
task
.
parallel
([
'ncc_babel_bundle_packages'
],
opts
)
await
task
.
parallel
([
'copy_react_server_dom_webpack'
])
await
task
.
parallel
([
'copy_react_server_dom_webpack'
])
}
}
...
...
scripts/check-pre-compiled.bat
0 → 100644
View file @
ee220730
copy node_modules\webpack5\lib\hmr\HotModuleReplacement.runtime.js packages\next\bundles\webpack\packages\
copy node_modules\webpack5\lib\hmr\JavascriptHotModuleReplacement.runtime.js packages\next\bundles\webpack\packages\
copy node_modules\webpack5\hot\lazy-compilation-node.js packages\next\bundles\webpack\packages\
copy node_modules\webpack5\hot\lazy-compilation-web.js packages\next\bundles\webpack\packages\
yarn --cwd packages/next ncc-compiled
rem Make sure to exit with 1 if there are changes after running ncc-compiled
rem step to ensure we get any changes committed
scripts/check-pre-compiled.sh
View file @
ee220730
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
cp
node_modules/webpack5/lib/hmr/HotModuleReplacement.runtime.js packages/next/bundles/webpack/packages/
cp
node_modules/webpack5/lib/hmr/HotModuleReplacement.runtime.js packages/next/bundles/webpack/packages/
cp
node_modules/webpack5/lib/hmr/JavascriptHotModuleReplacement.runtime.js packages/next/bundles/webpack/packages/
cp
node_modules/webpack5/lib/hmr/JavascriptHotModuleReplacement.runtime.js packages/next/bundles/webpack/packages/
cp
node_modules/webpack5/hot/lazy-compilation-node.js packages/next/bundles/webpack/packages/
cp
node_modules/webpack5/hot/lazy-compilation-web.js packages/next/bundles/webpack/packages/
yarn
--cwd
packages/next ncc-compiled
yarn
--cwd
packages/next ncc-compiled
# Make sure to exit with 1 if there are changes after running ncc-compiled
# Make sure to exit with 1 if there are changes after running ncc-compiled
...
...
test/development/basic-basepath/next-dynamic.test.ts
View file @
ee220730
...
@@ -32,7 +32,7 @@ describe('basic next/dynamic usage', () => {
...
@@ -32,7 +32,7 @@ describe('basic next/dynamic usage', () => {
const
$
=
await
get
$
(
'/docs/dynamic/ssr'
)
const
$
=
await
get
$
(
'/docs/dynamic/ssr'
)
// Make sure the client side knows it has to wait for the bundle
// Make sure the client side knows it has to wait for the bundle
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
'
./components/hello1.js
'
'
dynamic/ssr.js -> ../../components/hello1
'
)
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
})
})
...
@@ -41,7 +41,7 @@ describe('basic next/dynamic usage', () => {
...
@@ -41,7 +41,7 @@ describe('basic next/dynamic usage', () => {
const
$
=
await
get
$
(
'/docs/dynamic/function'
)
const
$
=
await
get
$
(
'/docs/dynamic/function'
)
// Make sure the client side knows it has to wait for the bundle
// Make sure the client side knows it has to wait for the bundle
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
'
./components/hello1.js
'
'
dynamic/function.js -> ../../components/hello1
'
)
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
})
})
...
...
test/development/basic/next-dynamic.test.ts
View file @
ee220730
...
@@ -29,7 +29,7 @@ describe('basic next/dynamic usage', () => {
...
@@ -29,7 +29,7 @@ describe('basic next/dynamic usage', () => {
const
$
=
await
get
$
(
'/dynamic/ssr'
)
const
$
=
await
get
$
(
'/dynamic/ssr'
)
// Make sure the client side knows it has to wait for the bundle
// Make sure the client side knows it has to wait for the bundle
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
'
./components/hello1.js
'
'
dynamic/ssr.js -> ../../components/hello1
'
)
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
})
})
...
@@ -38,7 +38,7 @@ describe('basic next/dynamic usage', () => {
...
@@ -38,7 +38,7 @@ describe('basic next/dynamic usage', () => {
const
$
=
await
get
$
(
'/dynamic/function'
)
const
$
=
await
get
$
(
'/dynamic/function'
)
// Make sure the client side knows it has to wait for the bundle
// Make sure the client side knows it has to wait for the bundle
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
dynamicIds
).
toContain
(
'
./components/hello1.js
'
'
dynamic/function.js -> ../../components/hello1
'
)
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World 1/
)
})
})
...
...
test/integration/app-document-add-hmr/test/index.test.js
View file @
ee220730
...
@@ -7,7 +7,6 @@ import { killApp, findPort, launchApp, check } from 'next-test-utils'
...
@@ -7,7 +7,6 @@ import { killApp, findPort, launchApp, check } from 'next-test-utils'
const
appDir
=
join
(
__dirname
,
'../'
)
const
appDir
=
join
(
__dirname
,
'../'
)
const
appPage
=
join
(
appDir
,
'pages/_app.js'
)
const
appPage
=
join
(
appDir
,
'pages/_app.js'
)
const
indexPage
=
join
(
appDir
,
'pages/index.js'
)
const
documentPage
=
join
(
appDir
,
'pages/_document.js'
)
const
documentPage
=
join
(
appDir
,
'pages/_document.js'
)
let
appPort
let
appPort
...
@@ -21,10 +20,8 @@ describe('_app/_document add HMR', () => {
...
@@ -21,10 +20,8 @@ describe('_app/_document add HMR', () => {
afterAll
(()
=>
killApp
(
app
))
afterAll
(()
=>
killApp
(
app
))
it
(
'should HMR when _app is added'
,
async
()
=>
{
it
(
'should HMR when _app is added'
,
async
()
=>
{
let
indexContent
=
await
fs
.
readFile
(
indexPage
)
try
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
const
browser
=
await
webdriver
(
appPort
,
'/'
)
try
{
const
html
=
await
browser
.
eval
(
'document.documentElement.innerHTML'
)
const
html
=
await
browser
.
eval
(
'document.documentElement.innerHTML'
)
expect
(
html
).
not
.
toContain
(
'custom _app'
)
expect
(
html
).
not
.
toContain
(
'custom _app'
)
expect
(
html
).
toContain
(
'index page'
)
expect
(
html
).
toContain
(
'index page'
)
...
@@ -50,16 +47,19 @@ describe('_app/_document add HMR', () => {
...
@@ -50,16 +47,19 @@ describe('_app/_document add HMR', () => {
:
html
:
html
},
'success'
)
},
'success'
)
}
finally
{
}
finally
{
await
fs
.
writeFile
(
indexPage
,
indexContent
)
await
fs
.
remove
(
appPage
)
await
fs
.
remove
(
appPage
)
await
check
(
async
()
=>
{
const
html
=
await
browser
.
eval
(
'document.documentElement.innerHTML'
)
return
!
html
.
includes
(
'custom _app'
)
&&
html
.
includes
(
'index page'
)
?
'restored'
:
html
},
'restored'
)
}
}
})
})
it
(
'should HMR when _document is added'
,
async
()
=>
{
it
(
'should HMR when _document is added'
,
async
()
=>
{
let
indexContent
=
await
fs
.
readFile
(
indexPage
)
try
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
const
browser
=
await
webdriver
(
appPort
,
'/'
)
try
{
const
html
=
await
browser
.
eval
(
'document.documentElement.innerHTML'
)
const
html
=
await
browser
.
eval
(
'document.documentElement.innerHTML'
)
expect
(
html
).
not
.
toContain
(
'custom _document'
)
expect
(
html
).
not
.
toContain
(
'custom _document'
)
expect
(
html
).
toContain
(
'index page'
)
expect
(
html
).
toContain
(
'index page'
)
...
@@ -101,8 +101,13 @@ describe('_app/_document add HMR', () => {
...
@@ -101,8 +101,13 @@ describe('_app/_document add HMR', () => {
:
html
:
html
},
'success'
)
},
'success'
)
}
finally
{
}
finally
{
await
fs
.
writeFile
(
indexPage
,
indexContent
)
await
fs
.
remove
(
documentPage
)
await
fs
.
remove
(
documentPage
)
await
check
(
async
()
=>
{
const
html
=
await
browser
.
eval
(
'document.documentElement.innerHTML'
)
return
!
html
.
includes
(
'custom _document'
)
&&
html
.
includes
(
'index page'
)
?
'restored'
:
html
},
'restored'
)
}
}
})
})
})
})
test/integration/next-dynamic-lazy-compilation/.babelrc
0 → 100644
View file @
ee220730
{
"presets": ["next/babel"]
}
test/integration/next-dynamic-lazy-compilation/apples/index.js
0 → 100644
View file @
ee220730
export
default
'foobar'
test/integration/next-dynamic-lazy-compilation/components/four.js
0 → 100644
View file @
ee220730
export
default
()
=>
{
return
'4'
}
test/integration/next-dynamic-lazy-compilation/components/one.js
0 → 100644
View file @
ee220730
import
something
from
'../apples'
export
default
()
=>
{
// have to do something with module so it is not tree shaken
console
.
log
(
something
)
return
'1'
}
test/integration/next-dynamic-lazy-compilation/components/three.js
0 → 100644
View file @
ee220730
export
default
()
=>
{
return
'3'
}
test/integration/next-dynamic-lazy-compilation/components/two.js
0 → 100644
View file @
ee220730
import
something
from
'../apples'
export
default
()
=>
{
// have to do something with module so it is not tree shaken
console
.
log
(
something
)
return
'2'
}
test/integration/next-dynamic-lazy-compilation/next.config.js
0 → 100644
View file @
ee220730
module
.
exports
=
{
webpack
(
config
,
{
isServer
,
dev
})
{
if
(
!
isServer
&&
dev
)
{
config
.
experiments
.
lazyCompilation
=
true
}
return
config
},
}
test/integration/next-dynamic-lazy-compilation/pages/index.js
0 → 100644
View file @
ee220730
import
dynamic
from
'next/dynamic'
import
{
useState
,
useEffect
}
from
'react'
import
FourDirect
from
'../components/four'
const
One
=
dynamic
(()
=>
import
(
'../components/one'
))
const
Two
=
dynamic
(()
=>
import
(
'../components/two'
))
const
Three
=
dynamic
(()
=>
import
(
'../components/three'
))
const
Four
=
dynamic
(()
=>
import
(
'../components/four'
))
if
(
typeof
window
!==
'undefined'
)
{
window
.
caughtErrors
=
''
const
origError
=
console
.
error
console
.
error
=
function
(...
args
)
{
window
.
caughtErrors
+=
args
.
join
(
' '
)
origError
(...
args
)
}
}
const
BEFORE_HYDRATION
=
typeof
document
!==
'undefined'
&&
document
.
getElementById
(
'foo'
).
innerHTML
const
Index
=
()
=>
{
const
[
firstRender
,
setFirstRender
]
=
useState
(
'the-server-value'
)
const
[
beforeHydration
,
setBeforeHydration
]
=
useState
(
'the-second-server-value'
)
useEffect
(()
=>
{
setFirstRender
(
document
.
getElementById
(
'foo'
).
innerHTML
)
setBeforeHydration
(
BEFORE_HYDRATION
)
},
[])
return
(
<>
<
div
id
=
"foo"
>
Index
<
One
/>
<
Two
/>
<
Three
/>
<
Four
/>
<
FourDirect
/>
<
/div
>
<
div
id
=
"first-render"
>
{
firstRender
}
<
/div
>
<
div
id
=
"before-hydration"
>
{
beforeHydration
}
<
/div
>
<
/
>
)
}
export
default
Index
test/integration/next-dynamic-lazy-compilation/test/index.test.js
0 → 100644
View file @
ee220730
/* eslint-env jest */
import
webdriver
from
'next-webdriver'
import
{
join
}
from
'path'
import
{
renderViaHTTP
,
findPort
,
launchApp
,
killApp
,
runNextCommand
,
nextServer
,
startApp
,
stopApp
,
}
from
'next-test-utils'
let
app
let
appPort
let
server
const
appDir
=
join
(
__dirname
,
'../'
)
function
runTests
()
{
it
(
'should render server value'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
expect
(
html
).
toMatch
(
/the-server-value/i
)
expect
(
html
).
toMatch
(
/the-second-server-value/i
)
})
it
(
'should render dynamic server rendered values before hydration'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
const
text
=
await
browser
.
elementByCss
(
'#before-hydration'
).
text
()
expect
(
text
).
toBe
(
'Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4'
)
expect
(
await
browser
.
eval
(
'window.caughtErrors'
)).
toBe
(
''
)
})
it
(
'should render dynamic server rendered values on client mount'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'/'
)
const
text
=
await
browser
.
elementByCss
(
'#first-render'
).
text
()
expect
(
text
).
toBe
(
'Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4'
)
expect
(
await
browser
.
eval
(
'window.caughtErrors'
)).
toBe
(
''
)
})
}
describe
(
'next/dynamic'
,
()
=>
{
describe
(
'dev mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
runTests
(
true
)
})
describe
(
'production mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
runNextCommand
([
'build'
,
appDir
])
app
=
nextServer
({
dir
:
appDir
,
dev
:
false
,
quiet
:
true
,
})
server
=
await
startApp
(
app
)
appPort
=
server
.
address
().
port
})
afterAll
(()
=>
stopApp
(
server
))
runTests
()
})
})
test/unit/next-babel-loader-prod.test.ts
View file @
ee220730
...
@@ -193,7 +193,7 @@ describe('next-babel-loader', () => {
...
@@ -193,7 +193,7 @@ describe('next-babel-loader', () => {
expect
(
expect
(
code
.
replace
(
/modules:
\[
".*
?
"/
,
'modules:["/path/to/page"'
)
code
.
replace
(
/modules:
\[
".*
?
"/
,
'modules:["/path/to/page"'
)
).
toMatchInlineSnapshot
(
).
toMatchInlineSnapshot
(
`"var _jsxFileName = \\"index.js\\";import React from \\"react\\";var __jsx = React.createElement;import dynamic from 'next/dynamic';const Comp = dynamic(() => import('comp'), { loadableGenerated: { webpack: () => [require.resolveWeak('comp')]
, modules:[\\"/path/to/page\\" + 'comp']
}});export default function Page(props) { return __jsx(Comp, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 7, columnNumber: 18 } });}"`
`"var _jsxFileName = \\"index.js\\";import React from \\"react\\";var __jsx = React.createElement;import dynamic from 'next/dynamic';const Comp = dynamic(() => import('comp'), { loadableGenerated: { webpack: () => [require.resolveWeak('comp')] }});export default function Page(props) { return __jsx(Comp, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 7, columnNumber: 18 } });}"`
)
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment