Feature: allow pre-parsed HTML nodes to be passed to HtmlWidget#1582
Open
CaptainDario wants to merge 3 commits into
Open
Feature: allow pre-parsed HTML nodes to be passed to HtmlWidget#1582CaptainDario wants to merge 3 commits into
HtmlWidget#1582CaptainDario wants to merge 3 commits into
Conversation
HtmlWidgetHtmlWidget
Contributor
Author
|
@daohoangson Any chance for this to be merged? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
parseHtmlToNodes()(a public, pure-Dart function) and a matchingparsedNodesparameter onHtmlWidget, 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
_parseHtmlis now public asparseHtmlToNodes(String html) → NodeList. It has no Flutter dependencies and is safe to call inside any isolate.HtmlWidgetaccepts an optionalparsedNodesparameter. When provided, the HTML-string-to-DOM parsing step is skipped in both the sync and async build paths, andbuildAsyncdefaults tofalse. In this case, the HTML-string parameter is completely ignored.NodeListis re-exported from the core library so consumers don't need a directpackage:htmldependency.Usage