fix: scope :extend inside @container like @media - #4542
dchaudhari7177 wants to merge 1 commit into
Conversation
Container has its own node type, and neither extend visitor had a visitContainer, so extends inside @container were collected into the enclosing scope. They matched selectors outside the block, and anything extended from inside one container leaked into the root and into other containers. Give Container the same extend scoping as Media. Fixes less#4540
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe extend visitors now scope ChangesContainer-scoped extends
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change scopes container-local extends without introducing an identified current-head regression. It is ready to merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
What:
Fixes #4540. An
:extendinside@containernow only matches selectors inside that same block, the rule@mediaalready follows.Containergot its own node type when container queries were added (#3811). The visitor dispatches onvisit${node.type}, and neitherExtendFinderVisitornorProcessExtendsVisitorhad avisitContainer. Extends inside@containerwere therefore collected into the enclosing scope and matched selectors anywhere. This addsvisitContainer/visitContainerOutto both visitors, delegating to theMediahandlers.With the snippet from the issue:
To be clear about what this doesn't do: extend never copies declarations into a block. The output the issue asks for (
.b { color: red; }inside the container) isn't something:extenddoes for@mediaeither. The empty@container container-name {}left behind is a separate, pre-existing difference: an empty@mediablock is removed byToCSSVisitor.visitMedia, which has noContainercounterpart either. It happens without any extend too, so I left it out of this PR.Why:
Before this change, extends leaked across container boundaries both ways. A selector extended inside one
@containergot added to rulesets at the top level and inside unrelated@containerblocks.Tests:
New
packages/test-data/tests-unit/extend-containerfixture, modelled onextend-media. It covers:.ext1 allfrom inside;.all:extend(.ext1 all), which should still reach into both containers;I used sibling containers rather than nesting them, so the fixture doesn't pin how nested named container queries are merged.
Running this fixture without the fix shows the leak.
.card-narrowand.card-wideget added to top-level.ext1 .ext2and to each other's container, and.bjoins.aat the root:eslintis clean onextend-visitor.js. I ran the Node test suite only, not the headless-browser tests.Checklist:
Summary by CodeRabbit
Bug Fixes
:extendbehavior inside CSS container queries.Tests