Skip to content

Commit 6376f62

Browse files
authored
Remove trailing space for void elements (preactjs#282)
* remove trailing space for void elements * add changeset * update tests * Update gentle-trains-attack.md
1 parent 0b04860 commit 6376f62

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.changeset/gentle-trains-attack.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'preact-render-to-string': major
3+
---
4+
5+
Remove trailing space for void_elements, this could fail some test_assertions as
6+
`<img />` will become `<img/>`, the other `VOID_ELEMENTS` this will be applied for
7+
can be found [here](https://github.com/preactjs/preact-render-to-string/blob/remove-trailing-space/src/index.js#L368-L385)

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
357357

358358
// Emit self-closing tag for empty void elements:
359359
if (!html && SELF_CLOSING.has(type)) {
360-
return s + ' />';
360+
return s + '/>';
361361
}
362362

363363
return s + '>' + html + '</' + type + '>';

test/render.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('render', () => {
116116

117117
it('should serialize defaultChecked prop to the checked attribute', () => {
118118
let rendered = render(<input type="checkbox" defaultChecked />),
119-
expected = `<input type="checkbox" checked />`;
119+
expected = `<input type="checkbox" checked/>`;
120120

121121
expect(rendered).to.equal(expected);
122122
});
@@ -247,7 +247,7 @@ describe('render', () => {
247247
<wbr />
248248
</div>
249249
),
250-
expected = `<div><input type="text" /><wbr /></div>`;
250+
expected = `<div><input type="text"/><wbr/></div>`;
251251

252252
expect(rendered).to.equal(expected);
253253
});

0 commit comments

Comments
 (0)