Skip to content

Commit 0b41fba

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

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

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

+13-1
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 {
@@ -260,14 +261,25 @@ impl Fold for NextDynamicPatcher {
260261
has_ssr_false = true
261262
}
262263
}
264+
if sym == "suspense" {
265+
if let Some(Lit::Bool(Bool {
266+
value: true,
267+
span: _,
268+
})) = match &**value {
269+
Expr::Lit(lit) => Some(lit),
270+
_ => None,
271+
} {
272+
has_suspense = true
273+
}
274+
}
263275
}
264276
}
265277
}
266278
props.extend(options_props.iter().cloned());
267279
}
268280
}
269281

270-
if has_ssr_false && self.is_server {
282+
if has_ssr_false && !has_suspense && self.is_server {
271283
expr.args[0] = Lit::Null(Null { span: DUMMY_SP }).as_arg();
272284
}
273285

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)