Skip to content

fix: support html 0.15.7 by matching selectors via SelectorEvaluator - #1516

Open
Mastermegamind wants to merge 1 commit into
Sub6Resources:masterfrom
Mastermegamind:fix/html-0-15-7-selector-matches
Open

Mastermegamind wants to merge 1 commit into
Sub6Resources:masterfrom
Mastermegamind:fix/html-0-15-7-selector-matches

Conversation

@Mastermegamind

Copy link
Copy Markdown

The problem

html 0.15.7 removed the top-level matches(Element, String) from lib/src/query_selector.dart, keeping only the SelectorEvaluator.matches method. StyledElement.matches calls the removed function, so flutter_html no longer compiles against html 0.15.7:

package:html/src/query_selector.dart:31:17: Error: Method not found: 'matches'.
      return qs.matches(element, selector);
                ^^^^^^^

The declared constraint is html: ^0.15.5, so pub resolves 0.15.7 by default. Downstream projects pick this up on their next pub upgrade with no constraint violation to warn them, and the only workaround available today is a dependency_overrides entry pinning html back to 0.15.6.

This is the TODO immediately above that import coming true.

The change

Parse the selector with csslib — already a direct dependency of this package — and match with SelectorEvaluator, which is present and unchanged across html 0.15.x.

Because SelectorEvaluator.matches exists in both 0.15.6 and 0.15.7, this works on either side of the removal and needs no constraint bump.

The implementation_imports ignore and its TODO stay as they are: SelectorEvaluator is only reachable through that path, so this narrows the exposure to the private API rather than eliminating it.

Verification

Ran this package's own test suite against both html versions, before and after:

html 0.15.6 html 0.15.7
master 232 passed, 1 failed 13 passed, 11 failed
this PR 232 passed, 1 failed 232 passed, 1 failed

The patch restores 0.15.7 to exact parity with the 0.15.6 baseline.

The single remaining failure — whitespace_test.dart, "extra newlines aren't added unnecessarily for details/summary tags" — is pre-existing on master and unrelated to this change; it fails identically on unpatched master with html 0.15.6.

html 0.15.7 removed the top-level `matches(Element, String)` from
`lib/src/query_selector.dart`, keeping only `SelectorEvaluator.matches`.
`StyledElement.matches` called the removed function, so flutter_html no
longer compiles against html 0.15.7:

    Error: Method not found: 'matches'.
    package:html/src/query_selector.dart

The declared constraint is `html: ^0.15.5`, so pub resolves 0.15.7 by
default and any downstream project picks up the break on its next
`pub upgrade`. The only workaround available today is a dependency
override pinning html to 0.15.6.

This parses the selector with csslib — already a direct dependency — and
matches with `SelectorEvaluator`, which is present and unchanged across
html 0.15.x. That makes it work on either side of the removal, so it needs
no constraint bump.

This is the TODO immediately above the import coming true; the
implementation import stays, since SelectorEvaluator is only reachable
through it.

Verified against the package's own suite:

    html 0.15.6, before this change:  232 passed, 1 failed
    html 0.15.7, before this change:   13 passed, 11 failed
    html 0.15.6, after this change:   232 passed, 1 failed
    html 0.15.7, after this change:   232 passed, 1 failed

The single remaining failure (whitespace_test.dart, details/summary
newlines) is pre-existing on master and unrelated.
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.

2 participants