Skip to content

fix: stop relying on package:html internals for selector matching - #1519

Closed
Eder-Queiroz wants to merge 1 commit into
Sub6Resources:masterfrom
Eder-Queiroz:fix/stop-using-html-package-internals
Closed

Eder-Queiroz wants to merge 1 commit into
Sub6Resources:masterfrom
Eder-Queiroz:fix/stop-using-html-package-internals

Conversation

@Eder-Queiroz

Copy link
Copy Markdown

Summary

StyledElement.matches() calls package:html/src/query_selector.dart's matches() via an implementation_imports-ignored import (the code even has a TODO acknowledging this is risky). That file lives under html's private lib/src/ and isn't covered by semver guarantees — its top-level matches() function was removed as "unused" internal code in html 0.15.7 (dart-lang/tools#2518), which breaks compilation of flutter_html 3.0.0 for anyone who resolves a fresh html version (no lockfile, or flutter pub upgrade):

Error: Method not found: 'matches'.
      return qs.matches(element, selector);

This is already affecting users — see dart-lang/tools#2574.

Fix

Vendors the small CSS selector evaluator from package:html's internal query_selector.dart into a new lib/src/css_selector_matcher.dart, built only on package:html's public Element/Node API and package:csslib's public selector AST (SelectorGroup, Visitor, etc.). StyledElement.matches() now calls this local matcher instead of reaching into html's internals, so a future breaking change to html's private files can no longer break flutter_html.

Behavior is unchanged — the evaluator logic (combinators, pseudo-classes, attribute selectors, nth-child, etc.) is copied as-is from the html package's implementation (MIT-licensed, attribution comment included in the new file).

Test plan

  • flutter analyze — no issues
  • flutter test — all 233 existing tests pass (including selector-dependent tests like tag/class matching for tagsList)
  • Verified flutter pub get now resolves html 0.15.7 cleanly and the package compiles

StyledElement.matches() called package:html/src/query_selector.dart's
matches() via an implementation_imports-ignored import. That file is
under html's private lib/src/ and isn't covered by its semver
guarantees; its top-level matches() was removed as "unused" internal
code in html 0.15.7, breaking compilation for anyone pulling a fresh
`html` resolution (dart-lang/tools#2574).

Vendor the small CSS selector evaluator into
lib/src/css_selector_matcher.dart, built only on package:html's public
Element/Node API and package:csslib's public selector AST, so
flutter_html no longer depends on html's internals.
@Eder-Queiroz

Copy link
Copy Markdown
Author

Closing in favor of #1516, which fixes the same issue with a much smaller diff by calling SelectorEvaluator directly instead of vendoring the selector-matching logic. That approach reuses html's implementation as-is (no duplicated/frozen copy to keep in sync with future upstream fixes) and is easier to review.

Our approach here removes the last dependency on package:html/src/* entirely, so it's structurally safer against a future internal rename/removal in html — but that's a smaller, more speculative benefit against a real maintenance cost (duplicated code), so #1516 seems like the better fix to merge for this bug. Thanks for taking a look either way!

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