Skip to content

Commit

Permalink
fix: render undefined html as the empty string (#13092)
Browse files Browse the repository at this point in the history
Fix #13069

---------

Co-authored-by: adiGuba <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2024
1 parent d776e52 commit b70d12c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-mails-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: render undefined html as the empty string
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/dom/blocks/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function html(node, get_value, svg, mathml, skip_warning) {
var effect;

block(() => {
if (value === (value = get_value())) {
if (value === (value = get_value() ?? '')) {
if (hydrating) {
hydrate_next();
}
Expand Down
5 changes: 3 additions & 2 deletions packages/svelte/src/internal/server/blocks/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { hash } from '../../../utils.js';
* @param {string} value
*/
export function html(value) {
var open = DEV ? `<!--${hash(String(value ?? ''))}-->` : '<!---->';
return `${open}${value}<!---->`;
var html = String(value ?? '');
var open = DEV ? `<!--${hash(html)}-->` : '<!---->';
return open + html + '<!---->';
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default test({

ssrHtml: `
<editor contenteditable="true"><b>world</b></editor>
<p>hello null</p>
<p>hello </p>
`,

async test({ assert, component, target, window }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '../../test';

export default test({
html: ''
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{@html undefined}

0 comments on commit b70d12c

Please sign in to comment.