Skip to content

fix: Workaround for the TextBoxComponent entering an endless loop - #3939

Merged
erickzanardo merged 1 commit into
mainfrom
fix/erick/text-box-web-render-workaround
Jul 1, 2026
Merged

erickzanardo merged 1 commit into
mainfrom
fix/erick/text-box-web-render-workaround

Conversation

@erickzanardo

@erickzanardo erickzanardo commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Description

This PR adds an workaround for and issue that was cause the TextBoxComponent enter a never ending loop when rendering some texts.

This is being cause due the result TextRange from the TextPainter sometimes reporting an incorrect result, very mostly likely because of the floating number innacuracy in javascript.

An issue was open in the Flutter repository to track this issue: flutter/flutter#188874

This workaround could be removed/revisited depending on the outcome of such issue.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #3938

@erickzanardo
erickzanardo requested a review from a team July 1, 2026 18:29
@erickzanardo
erickzanardo merged commit 0b42aa0 into main Jul 1, 2026
10 checks passed
@erickzanardo
erickzanardo deleted the fix/erick/text-box-web-render-workaround branch July 1, 2026 20:11
spydon added a commit that referenced this pull request Oct 1, 2026
The rich text document pipeline (`DocumentRoot`, `ParagraphNode`,
`HeaderNode`, and therefore `flame_markdown`) was the last place in
Flame that broke lines itself. Its layout builder split on ASCII spaces,
re-measured every tentative line with a fresh `TextPainter`, could not
wrap CJK, threw on `TextAlign.justify`, lost kerning and ligatures at
span boundaries, and needed glue heuristics for punctuation that were
patched again in #4060 after #3192 and #3939.

Since `InlineTextStyle` always renders through `TextPaint`, that
pipeline can hand the whole block to Flutter's paragraph engine without
losing any capability:

- `InlineTextNode.layoutBuilder` is replaced by `InlineSpan
toInlineSpan()`. `PlainTextNode` and `GroupTextNode` build a `TextSpan`
tree, the wrapper nodes delegate to their child.
- `TextBlockNode.format` lays out one `TextPainter` per block and
returns the new `ParagraphTextElement`, which exposes `lines` and
`lineMetrics`. Justify, CJK wrapping, hard line breaks, and shaping
across differently styled spans now work.
- `TextElement` gained a no-op `dispose()`, forwarded by `GroupElement`,
which `ParagraphTextElement` uses to release its painter.
- `TextBoxComponent` lays out a dedicated painter for wrapping and reads
lines through `ParagraphTextElement`. It previously called
`layout(maxWidth:)` on the painter shared through the `TextPaint` cache,
so the wrapped layout leaked into later `format` calls for the same
string. Per-line rendering, `align`, `growingBox` and the typewriter
effect are unchanged.

---------

Co-authored-by: Luan Nico <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: TextBoxComponent crashes with the text in the examples

2 participants