Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Copy Markdown
Contributor

@jsamr jsamr Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test that proves that two spaces are still collapsed into one. In other words

the following:

<span><span><strong>foo</strong>  </span><span><strong>bar</strong></span></span>

renders the same as your example:

<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ describe('collapse function', () => {
const ttree = makeTTree('<span><span>foo </span><span> bar</span></span>');
expect(ttree).toMatchSnapshot();
});
it('should preserve boundary spaces wrapped in nested inline phrasing tags', () => {
const ttree = makeTTree(
'<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>'
);
const [firstSpan, secondSpan] = ttree.children;
expect(firstSpan.tagName).toBe('span');
expect(firstSpan.children).toHaveLength(2);
expect((firstSpan.children[0] as TTextImpl).data).toBe('foo');
expect((firstSpan.children[1] as TTextImpl).data).toBe(' ');
expect(secondSpan.tagName).toBe('span');
expect(secondSpan.children).toHaveLength(1);
expect((secondSpan.children[0] as TTextImpl).data).toBe('bar');
});
Comment on lines +40 to +52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a snaphot, like every other test in this file.

it('should handle nested anchors', () => {
const ttree = makeTTree(nestedHyperlinksSource);
expect(ttree).toMatchSnapshot();
Expand Down
8 changes: 6 additions & 2 deletions packages/transient-render-engine/src/tree/TPhrasingCtor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ TPhrasingCtor.prototype.collapseChildren = function collapseChildren() {
}
previous = childK;
});
this.trimLeft();
this.trimRight();
// Preserve boundary spaces for named inline wrappers (e.g. styled spans) so
// their parent phrasing container can collapse sibling boundaries correctly.
if (this.tagName === null) {
this.trimLeft();
this.trimRight();
}
return null;
};

Expand Down
Loading