Skip to content

Commit 0de3c06

Browse files
committed
Fix SWC dynamic transform with suspense but without ssr
1 parent e05a95a commit 0de3c06

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

packages/next-swc/crates/core/src/next_dynamic.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ impl Fold for NextDynamicPatcher {
226226
})))];
227227

228228
let mut has_ssr_false = false;
229+
let mut has_suspense = false;
229230

230231
if expr.args.len() == 2 {
231232
if let Expr::Object(ObjectLit {
@@ -253,21 +254,28 @@ impl Fold for NextDynamicPatcher {
253254
if let Some(Lit::Bool(Bool {
254255
value: false,
255256
span: _,
256-
})) = match &**value {
257-
Expr::Lit(lit) => Some(lit),
258-
_ => None,
259-
} {
257+
})) = value.as_lit()
258+
{
260259
has_ssr_false = true
261260
}
262261
}
262+
if sym == "suspense" {
263+
if let Some(Lit::Bool(Bool {
264+
value: true,
265+
span: _,
266+
})) = value.as_lit()
267+
{
268+
has_suspense = true
269+
}
270+
}
263271
}
264272
}
265273
}
266274
props.extend(options_props.iter().cloned());
267275
}
268276
}
269277

270-
if has_ssr_false && self.is_server {
278+
if has_ssr_false && !has_suspense && self.is_server {
271279
expr.args[0] = Lit::Null(Null { span: DUMMY_SP }).as_arg();
272280
}
273281

packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/input.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ const DynamicClientOnlyComponent = dynamic(
99
() => import('../components/hello'),
1010
{ ssr: false }
1111
)
12+
13+
const DynamicClientOnlyComponentWithSuspense = dynamic(
14+
() => import('../components/hello'),
15+
{ ssr: false, suspense: true }
16+
)

packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-dev.js

+10
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ const DynamicClientOnlyComponent = dynamic(()=>import('../components/hello')
1717
},
1818
ssr: false
1919
});
20+
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
21+
, {
22+
loadableGenerated: {
23+
modules: [
24+
"some-file.js -> " + "../components/hello"
25+
]
26+
},
27+
ssr: false,
28+
suspense: true
29+
});

packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-prod.js

+10
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ const DynamicClientOnlyComponent = dynamic(()=>import('../components/hello')
1717
},
1818
ssr: false
1919
});
20+
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
21+
, {
22+
loadableGenerated: {
23+
webpack: ()=>[
24+
require.resolveWeak("../components/hello")
25+
]
26+
},
27+
ssr: false,
28+
suspense: true
29+
});

packages/next-swc/crates/core/tests/fixture/next-dynamic/with-options/output-server.js

+10
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ const DynamicClientOnlyComponent = dynamic(null, {
1616
},
1717
ssr: false
1818
});
19+
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
20+
, {
21+
loadableGenerated: {
22+
modules: [
23+
"some-file.js -> " + "../components/hello"
24+
]
25+
},
26+
ssr: false,
27+
suspense: true
28+
});

0 commit comments

Comments
 (0)