Skip to content

Commit 5855a72

Browse files
leineveber5ZYSZ3K
authored andcommitted
fix(transient-render-engine): preserve nested inline boundary spaces
Keep boundary spaces inside named inline wrappers until the parent phrasing node collapses sibling whitespace. Add a regression test for nested inline tags that previously rendered "foobar" instead of "foo bar". Made-with: Cursor
1 parent 8f403ca commit 5855a72

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/transient-render-engine/src/flow/__tests__/collapse.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ describe('collapse function', () => {
3737
const ttree = makeTTree('<span><span>foo </span><span> bar</span></span>');
3838
expect(ttree).toMatchSnapshot();
3939
});
40+
it('should preserve boundary spaces wrapped in nested inline phrasing tags', () => {
41+
const ttree = makeTTree(
42+
'<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>'
43+
);
44+
const [firstSpan, secondSpan] = ttree.children;
45+
expect(firstSpan.tagName).toBe('span');
46+
expect(firstSpan.children).toHaveLength(2);
47+
expect((firstSpan.children[0] as TTextImpl).data).toBe('foo');
48+
expect((firstSpan.children[1] as TTextImpl).data).toBe(' ');
49+
expect(secondSpan.tagName).toBe('span');
50+
expect(secondSpan.children).toHaveLength(1);
51+
expect((secondSpan.children[0] as TTextImpl).data).toBe('bar');
52+
});
4053
it('should handle nested anchors', () => {
4154
const ttree = makeTTree(nestedHyperlinksSource);
4255
expect(ttree).toMatchSnapshot();

packages/transient-render-engine/src/tree/TPhrasingCtor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ TPhrasingCtor.prototype.collapseChildren = function collapseChildren() {
4848
}
4949
previous = childK;
5050
});
51-
this.trimLeft();
52-
this.trimRight();
51+
// Preserve boundary spaces for named inline wrappers (e.g. styled spans) so
52+
// their parent phrasing container can collapse sibling boundaries correctly.
53+
if (this.tagName === null) {
54+
this.trimLeft();
55+
this.trimRight();
56+
}
5357
return null;
5458
};
5559

0 commit comments

Comments
 (0)