Skip to content

Fix bug in attribute selector parsing#20303

Merged
RobinMalfait merged 4 commits into
mainfrom
fix/selector-parser
Jul 3, 2026
Merged

Fix bug in attribute selector parsing#20303
RobinMalfait merged 4 commits into
mainfrom
fix/selector-parser

Conversation

@RobinMalfait

Copy link
Copy Markdown
Member

This PR fixes a bug in the selector parser where an attribute selector followed by a type selector inside a compound selector resulted in the wrong result.

Given you have this CSS:

[data-foo]div {}

Then parsing it before this PR, would result in:

{
  kind: 'compound',
  nodes: [
    { kind: 'selector', value: '[data-foo]div' },
  ],
},

But with this PR, it's properly split:

{
  kind: 'compound',
  nodes: [
    { kind: 'selector', value: '[data-foo]' },
    { kind: 'selector', value: 'div' },
  ],
},

I also tweaked some of the comments in the parser that are unrelated, but I was there already.

Test plan

  1. Added a regression test
  2. All other tests should pass

Otherwise if we have `[attribute]div` we would get:

Before:
```
{
  kind: 'compound',
  nodes: [
    { kind: 'selector', value: '[data-foo]div' },
  ],
},
```

After:
```
{
  kind: 'compound',
  nodes: [
    { kind: 'selector', value: '[data-foo]' },
    { kind: 'selector', value: 'div' },
  ],
},
```
@RobinMalfait RobinMalfait requested a review from a team as a code owner July 3, 2026 19:06
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the fix is a minimal, well-targeted one-line change to the attribute selector branch of the parser, backed by three new regression tests.

The change replaces a single assignment (buffer += ...) with a direct append(selector(...)) call, exactly scoping the fix to the broken code path. Existing tests still pass, and the new tests cover the reported case and adjacent variants. No other logic in the parser is disturbed.

No files require special attention.

Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c8193aa1-40dc-4ca3-a52f-f30db5cdfc71

📥 Commits

Reviewing files that changed from the base of the PR and between 47b4ff9 and 220b4c7.

📒 Files selected for processing (1)
  • CHANGELOG.md

Walkthrough

This PR changes selector parsing so attribute selectors are emitted as their own selector nodes from the input slice, rather than being merged into the current buffer. It also refreshes inline comments in the parser, updates tests for compound selectors with adjacent attribute and type selectors, and adds a changelog entry for the parsing fix.

Changes

Related issues: None specified

Related PRs: None specified

Suggested labels: bug, tests

Suggested reviewers: tailwindlabs maintainers

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing attribute selector parsing in the selector parser.
Description check ✅ Passed The description matches the changeset and explains the selector parsing bug fix and regression test.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@RobinMalfait RobinMalfait merged commit 67c745e into main Jul 3, 2026
8 checks passed
@RobinMalfait RobinMalfait deleted the fix/selector-parser branch July 3, 2026 19:13
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