Skip to content

Commit

Permalink
Fix SWC dynamic transform with suspense but without ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed May 11, 2022
1 parent e05a95a commit 0b41fba
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/next-swc/crates/core/src/next_dynamic.rs
Expand Up @@ -226,6 +226,7 @@ impl Fold for NextDynamicPatcher {
})))];

let mut has_ssr_false = false;
let mut has_suspense = false;

if expr.args.len() == 2 {
if let Expr::Object(ObjectLit {
Expand Down Expand Up @@ -260,14 +261,25 @@ impl Fold for NextDynamicPatcher {
has_ssr_false = true
}
}
if sym == "suspense" {
if let Some(Lit::Bool(Bool {
value: true,
span: _,
})) = match &**value {
Expr::Lit(lit) => Some(lit),
_ => None,
} {
has_suspense = true
}
}
}
}
}
props.extend(options_props.iter().cloned());
}
}

if has_ssr_false && self.is_server {
if has_ssr_false && !has_suspense && self.is_server {
expr.args[0] = Lit::Null(Null { span: DUMMY_SP }).as_arg();
}

Expand Down
Expand Up @@ -9,3 +9,8 @@ const DynamicClientOnlyComponent = dynamic(
() => import('../components/hello'),
{ ssr: false }
)

const DynamicClientOnlyComponentWithSuspense = dynamic(
() => import('../components/hello'),
{ ssr: false, suspense: true }
)
Expand Up @@ -17,3 +17,13 @@ const DynamicClientOnlyComponent = dynamic(()=>import('../components/hello')
},
ssr: false
});
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
, {
loadableGenerated: {
modules: [
"some-file.js -> " + "../components/hello"
]
},
ssr: false,
suspense: true
});
Expand Up @@ -17,3 +17,13 @@ const DynamicClientOnlyComponent = dynamic(()=>import('../components/hello')
},
ssr: false
});
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
, {
loadableGenerated: {
webpack: ()=>[
require.resolveWeak("../components/hello")
]
},
ssr: false,
suspense: true
});
Expand Up @@ -16,3 +16,13 @@ const DynamicClientOnlyComponent = dynamic(null, {
},
ssr: false
});
const DynamicClientOnlyComponentWithSuspense = dynamic(()=>import('../components/hello')
, {
loadableGenerated: {
modules: [
"some-file.js -> " + "../components/hello"
]
},
ssr: false,
suspense: true
});

0 comments on commit 0b41fba

Please sign in to comment.