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
9836429b
Unverified
Commit
9836429b
authored
Jan 11, 2022
by
Tobias Koppers
Committed by
GitHub
Jan 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop dynamic import with `ssr: false` on server-side (#32606)
parent
600f1133
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
130 additions
and
3 deletions
+130
-3
next_dynamic.rs
packages/next-swc/crates/core/src/next_dynamic.rs
+40
-3
fixture.rs
packages/next-swc/crates/core/tests/fixture.rs
+14
-0
output-server.js
.../fixture/next-dynamic/duplicated-imports/output-server.js
+12
-0
output-server.js
...xture/next-dynamic/member-with-same-name/output-server.js
+8
-0
output-server.js
...re/tests/fixture/next-dynamic/no-options/output-server.js
+6
-0
input.js
...tes/core/tests/fixture/next-dynamic/with-options/input.js
+5
-0
output-dev.js
...ore/tests/fixture/next-dynamic/with-options/output-dev.js
+9
-0
output-prod.js
...re/tests/fixture/next-dynamic/with-options/output-prod.js
+9
-0
output-server.js
.../tests/fixture/next-dynamic/with-options/output-server.js
+16
-0
output-server.js
...ests/fixture/next-dynamic/wrapped-import/output-server.js
+11
-0
No files found.
packages/next-swc/crates/core/src/next_dynamic.rs
View file @
9836429b
...
...
@@ -4,10 +4,11 @@ use pathdiff::diff_paths;
use
swc_atoms
::
js_word
;
use
swc_common
::{
FileName
,
DUMMY_SP
};
use
swc_ecmascript
::
ast
::{
ArrayLit
,
ArrowExpr
,
BinExpr
,
BinaryOp
,
BlockStmtOrExpr
,
CallExpr
,
Expr
,
ExprOrSpread
,
ExprOrSuper
,
Ident
,
ImportDecl
,
ImportSpecifier
,
KeyValueProp
,
Lit
,
MemberExpr
,
ObjectLit
,
Prop
,
PropName
,
PropOrSpread
,
Str
,
StrKind
,
ArrayLit
,
ArrowExpr
,
BinExpr
,
BinaryOp
,
BlockStmtOrExpr
,
Bool
,
CallExpr
,
Expr
,
ExprOrSpread
,
ExprOrSuper
,
Ident
,
ImportDecl
,
ImportSpecifier
,
KeyValueProp
,
Lit
,
MemberExpr
,
Null
,
ObjectLit
,
Prop
,
PropName
,
PropOrSpread
,
Str
,
StrKind
,
};
use
swc_ecmascript
::
utils
::
ExprFactory
;
use
swc_ecmascript
::
utils
::{
ident
::{
Id
,
IdentLike
},
HANDLER
,
...
...
@@ -236,16 +237,52 @@ impl Fold for NextDynamicPatcher {
value
:
generated
,
})))];
let
mut
has_ssr_false
=
false
;
if
expr
.args
.len
()
==
2
{
if
let
Expr
::
Object
(
ObjectLit
{
props
:
options_props
,
..
})
=
&*
expr
.args
[
1
]
.expr
{
for
prop
in
options_props
.iter
()
{
if
let
Some
(
KeyValueProp
{
key
,
value
})
=
match
prop
{
PropOrSpread
::
Prop
(
prop
)
=>
match
&**
prop
{
Prop
::
KeyValue
(
key_value_prop
)
=>
Some
(
key_value_prop
),
_
=>
None
,
},
_
=>
None
,
}
{
if
let
Some
(
Ident
{
sym
,
span
:
_
,
optional
:
_
,
})
=
match
key
{
PropName
::
Ident
(
ident
)
=>
Some
(
ident
),
_
=>
None
,
}
{
if
sym
==
"ssr"
{
if
let
Some
(
Lit
::
Bool
(
Bool
{
value
:
false
,
span
:
_
,
}))
=
match
&**
value
{
Expr
::
Lit
(
lit
)
=>
Some
(
lit
),
_
=>
None
,
}
{
has_ssr_false
=
true
}
}
}
}
}
props
.extend
(
options_props
.iter
()
.cloned
());
}
}
if
has_ssr_false
&&
self
.is_server
{
expr
.args
[
0
]
=
Lit
::
Null
(
Null
{
span
:
DUMMY_SP
})
.as_arg
();
}
let
second_arg
=
ExprOrSpread
{
spread
:
None
,
expr
:
Box
::
new
(
Expr
::
Object
(
ObjectLit
{
...
...
packages/next-swc/crates/core/tests/fixture.rs
View file @
9836429b
...
...
@@ -34,6 +34,7 @@ fn amp_attributes_fixture(input: PathBuf) {
fn
next_dynamic_fixture
(
input
:
PathBuf
)
{
let
output_dev
=
input
.parent
()
.unwrap
()
.join
(
"output-dev.js"
);
let
output_prod
=
input
.parent
()
.unwrap
()
.join
(
"output-prod.js"
);
let
output_server
=
input
.parent
()
.unwrap
()
.join
(
"output-server.js"
);
test_fixture
(
syntax
(),
&
|
_tr
|
{
...
...
@@ -60,6 +61,19 @@ fn next_dynamic_fixture(input: PathBuf) {
&
input
,
&
output_prod
,
);
test_fixture
(
syntax
(),
&
|
_tr
|
{
next_dynamic
(
false
,
true
,
FileName
::
Real
(
PathBuf
::
from
(
"/some-project/src/some-file.js"
)),
Some
(
"/some-project/src"
.into
()),
)
},
&
input
,
&
output_server
,
);
}
#[fixture(
"tests/fixture/ssg/**/input.js"
)]
...
...
packages/next-swc/crates/core/tests/fixture/next-dynamic/duplicated-imports/output-server.js
0 → 100644
View file @
9836429b
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/member-with-same-name/output-server.js
0 → 100644
View file @
9836429b
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/no-options/output-server.js
0 → 100644
View file @
9836429b
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/with-options/input.js
View file @
9836429b
...
...
@@ -4,3 +4,8 @@ const DynamicComponentWithCustomLoading = dynamic(
()
=>
import
(
'../components/hello'
),
{
loading
:
()
=>
<
p
>
...
<
/p>
}
)
const
DynamicClientOnlyComponent
=
dynamic
(
()
=>
import
(
'../components/hello'
),
{
ssr
:
false
}
)
packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-dev.js
View file @
9836429b
...
...
@@ -8,3 +8,12 @@ const DynamicComponentWithCustomLoading = dynamic(()=>import("../components/hell
},
loading
:
()
=><
p
>
...
<
/p
>
});
const
DynamicClientOnlyComponent
=
dynamic
(()
=>
import
(
"../components/hello"
)
,
{
loadableGenerated
:
{
modules
:
[
"some-file.js -> "
+
"../components/hello"
]
},
ssr
:
false
});
\ No newline at end of file
packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-prod.js
View file @
9836429b
...
...
@@ -8,3 +8,12 @@ const DynamicComponentWithCustomLoading = dynamic(()=>import("../components/hell
},
loading
:
()
=><
p
>
...
<
/p
>
});
const
DynamicClientOnlyComponent
=
dynamic
(()
=>
import
(
"../components/hello"
)
,
{
loadableGenerated
:
{
webpack
:
()
=>
[
require
.
resolveWeak
(
"../components/hello"
)
]
},
ssr
:
false
});
\ No newline at end of file
packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-server.js
0 → 100644
View file @
9836429b
import
dynamic
from
'next/dynamic'
const
DynamicComponentWithCustomLoading
=
dynamic
(
()
=>
import
(
'../components/hello'
),
{
loadableGenerated
:
{
modules
:
[
'some-file.js -> '
+
'../components/hello'
],
},
loading
:
()
=>
<
p
>
...
<
/p>
,
}
)
const
DynamicClientOnlyComponent
=
dynamic
(
null
,
{
loadableGenerated
:
{
modules
:
[
'some-file.js -> '
+
'../components/hello'
],
},
ssr
:
false
,
})
packages/next-swc/crates/core/tests/fixture/next-dynamic/wrapped-import/output-server.js
0 → 100644
View file @
9836429b
import
dynamic
from
"next/dynamic"
;
const
DynamicComponent
=
dynamic
(
null
,
{
loadableGenerated
:
{
modules
:
[
"some-file.js -> "
+
"./components/hello"
]
},
loading
:
()
=>
null
,
ssr
:
false
});
\ No newline at end of file
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