Skip to content

Commit 1c65f6a

Browse files
authored
fix: prevent rendering <undefined> tags when children prop is not passed (#497)- Added null check in composite.js to prevent creating elements when component is undefined- Added test case to verify components without children don't render <undefined> tags- Fixes issue where <@children /> would create <undefined></undefined> when children prop is undefined (#589)
1 parent 444794a commit 1c65f6a

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

packages/ripple/src/runtime/internal/client/composite.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @import { Block } from '#client' */
22

33
import { branch, destroy_block, render, render_spread } from './blocks.js';
4-
import { COMPOSITE_BLOCK, NAMESPACE_URI, DEFAULT_NAMESPACE } from './constants.js';
4+
import { COMPOSITE_BLOCK, DEFAULT_NAMESPACE, NAMESPACE_URI } from './constants.js';
55
import { active_block, active_namespace, with_ns } from './runtime.js';
66
import { top_element_to_ns } from './utils.js';
77

@@ -32,8 +32,8 @@ export function composite(get_component, node, props) {
3232
var block = active_block;
3333
/** @type {ComponentFunction} */ (component)(anchor, props, block);
3434
});
35-
} else {
36-
// Custom element
35+
} else if (component != null) {
36+
// Custom element - only create if component is not null/undefined
3737
var run = () => {
3838
var block = /** @type {Block} */ (active_block);
3939

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { track } from 'ripple';
2+
3+
describe('bug reproduction #497', () => {
4+
it('should not render <undefined> tag when children is not passed', () => {
5+
component Span({ children, id: key = 2, ...props }) {
6+
const renderredHtml = track('');
7+
const refNode = (node) => {
8+
console.log(node.outerHTML);
9+
@renderredHtml = node.outerHTML;
10+
};
11+
<span {ref refNode} {...props}>
12+
<@children />
13+
</span>
14+
{@renderredHtml}
15+
}
16+
17+
component App() {
18+
<Span class="red" />
19+
}
20+
21+
render(App);
22+
23+
const span = container.querySelector('span');
24+
const undefinedTag = container.querySelector('undefined');
25+
26+
expect(span).toBeTruthy();
27+
expect(span.className).toBe('red');
28+
// The bug: undefined tag should not exist
29+
expect(undefinedTag).toBeNull();
30+
// The span should not contain <undefined></undefined> in its HTML
31+
expect(span.innerHTML).not.toContain('<undefined');
32+
});
33+
});

0 commit comments

Comments
 (0)