Skip to content

Commit

Permalink
fix: null/undefined signal child hydration now works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
LankyMoose committed Sep 19, 2024
1 parent 898d795 commit 15ede28
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/lib/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function hydrateDom(vNode: VNode) {
while (sibling && sibling.type === ELEMENT_TYPE.text) {
const sib = sibling
hydrationStack.bumpChildIndex()
const prevText = String(unwrap(prev.props.nodeValue))
const prevText = String(unwrap(prev.props.nodeValue) ?? "")
const dom = (prev.dom as Text).splitText(prevText.length)
sib.dom = dom
if (Signal.isSignal(sib.props.nodeValue)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/lib/src/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ function createChild(
sig: Signal<any> | null = null
): VNode | null {
if (
(typeof child === "string" && (child !== "" || sig)) ||
sig ||
(typeof child === "string" && child !== "") ||
typeof child === "number" ||
typeof child === "bigint"
) {
Expand Down
10 changes: 8 additions & 2 deletions sandbox/ssr/src/pages/index/+Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ export function Page() {
const [codeInput, setCodeInput] = useState(
"const x = () => <h1>Hello World!</h1>"
)
const compiled = signal("")
const compiled = signal<string | undefined>(undefined)
const compiled2 = signal<string | undefined>(undefined)
const compiled3 = signal<number | undefined>(undefined)
useEffect(() => {
compiled.value = "bar"
compiled2.value = "test"
compiled3.value = 123
}, [codeInput])
return (
<div className="p-6">
Expand All @@ -15,7 +19,9 @@ export function Page() {
oninput={(e) => setCodeInput(e.target.value)}
/>
<pre>
<code style="white-space:normal;">foo {compiled} baz</code>
<code style="white-space:normal;">
foo {compiled} {compiled2} baz {compiled3}
</code>
</pre>
</div>
)
Expand Down

0 comments on commit 15ede28

Please sign in to comment.