Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2618273

Browse files
augustjkrictic
andauthored
[labs/ssr-client] Avoid nullish logical assignment in hydrate-lit-html (#4312)
Co-authored-by: Peter Burns <[email protected]>
1 parent c28ebba commit 2618273

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.changeset/olive-otters-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lit-labs/ssr-client': patch
3+
---
4+
5+
Avoid nullish logical assignment in hydrate-lit-html which some minification process would not handle correctly. Fixes hydration errors in Next.js production bundles.

packages/labs/ssr-client/src/lib/hydrate-lit-html.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ export const hydrate = (
163163
}
164164
// Create a new ChildPart and push it onto the stack
165165
currentChildPart = openChildPart(rootValue, marker, stack, options);
166-
rootPart ??= currentChildPart;
166+
// Using nullish logical assignment below can cause next.js's swc to move
167+
// the `openChildPart()` call above behind the nullish check.
168+
// See https://github.com/lit/lit/issues/4289
169+
if (rootPart === undefined) {
170+
rootPart = currentChildPart;
171+
}
167172
rootPartMarker ??= marker;
168173
} else if (markerText.startsWith('lit-node')) {
169174
// Create and hydrate attribute parts into the current ChildPart on the

0 commit comments

Comments
 (0)