feat: add TText renderer to override all text nodes, including anonymous text - #46
keerbee-dev wants to merge 1 commit into
Conversation
|
Hi, it is a great idea! I'll get that reviewed this week |
|
Hi @keerbee-dev |
|
Hi, 5ZYSZ3K I’ll update the PR later this week when I have some time. |
| if (!custom && tnode.type === 'text') { | ||
| const textRenderer = this.customRenderers['TText']; | ||
| if (textRenderer) { | ||
| custom = textRenderer as any; |
There was a problem hiding this comment.
Definitely won't allow an any type assertion! That's a well established source of bugs, and it defies the purpose of using TypeScript.
|
|
||
| // Allow overriding all text nodes via TText | ||
| if (!custom && tnode.type === 'text') { | ||
| const textRenderer = this.customRenderers['TText']; |
There was a problem hiding this comment.
I also agree with Paweł that it should not be treated as a custom renderer, which are defined for HTML tags, not transient nodes. It's actually a lower level brick that would replace any TText rendering.
Summary
This PR adds support for a new special key
TTextin therenderersprop to override the rendering of all text nodes, including anonymous text (text without an enclosing HTML tag).The Problem
Currently, custom renderers are resolved only by
tagName. Anonymous text hastagName === null, so it cannot be intercepted. Developers must override every possible tag (p,span,div, …) and still miss anonymous text.Example
The Fix
Modify
RenderRegistry.getRendererConfigForTNodeto check forTTextwhentnode.type === 'text'and no custom renderer was found bytagName.Implementation