Skip to content

Feature: allow pre-parsed HTML nodes to be passed to HtmlWidget#1582

Open
CaptainDario wants to merge 3 commits into
daohoangson:masterfrom
CaptainDario:feature-allow_rendering_from_perprocessed_html
Open

Feature: allow pre-parsed HTML nodes to be passed to HtmlWidget#1582
CaptainDario wants to merge 3 commits into
daohoangson:masterfrom
CaptainDario:feature-allow_rendering_from_perprocessed_html

Conversation

@CaptainDario
Copy link
Copy Markdown
Contributor

Adds parseHtmlToNodes() (a public, pure-Dart function) and a matching parsedNodes parameter on HtmlWidget, so users can offload the HTML parsing to an isolate and pass the result directly to the widget.

Why

Rendering large HTML snippets causes main-thread jank. The package already offloads HTML-string-to-DOM parsing to a compute() isolate when the string exceeds 10k chars.
However, in some scenarios it is helpful to have your own isolate for HTML generation/parsing/processing/fetching (e.g, slow HTML generation, fetching from web resources, ...). In this case, it would be useful to also do the HTML -> NodeList conversion in that isolate instead of sending the string back to the main isolate, and that isolate in turn sends it back to a processing isolate of flutter_widget_from_html.

What changed

  • _parseHtml is now public as parseHtmlToNodes(String html) → NodeList. It has no Flutter dependencies and is safe to call inside any isolate.
  • HtmlWidget accepts an optional parsedNodes parameter. When provided, the HTML-string-to-DOM parsing step is skipped in both the sync and async build paths, and buildAsync defaults to false. In this case, the HTML-string parameter is completely ignored.
  • NodeList is re-exported from the core library so consumers don't need a direct package:html dependency.
  • No breaking changes, all tests pass.

Usage

// Inside your existing background isolate:
final nodes = parseHtmlToNodes(myHtml);

...

// Back on the main thread — HTML→DOM parsing is already done:
HtmlWidget("", parsedNodes: nodes)

@CaptainDario CaptainDario changed the title feat(core): allow pre-parsed HTML nodes to be passed to HtmlWidget Feature: allow pre-parsed HTML nodes to be passed to HtmlWidget Apr 12, 2026
@CaptainDario
Copy link
Copy Markdown
Contributor Author

@daohoangson Any chance for this to be merged?

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.

1 participant