Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit daa75fe

Browse files
committed
Response to second comments
1 parent 227d6cd commit daa75fe

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

index.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ const plugin = (opts = {}) => {
5757
// Flag to track if container context like sticky has been added
5858
let hasAddedContainerContext = false;
5959

60+
const isSameMediaQuery = (mq1, mq2) => {
61+
return mq1.params === mq2.params &&
62+
mq1.source?.start?.line === mq2.source?.start?.line;
63+
};
64+
6065
/**
6166
* Adds a container context with `position: relative` and `contain: layout` if required.
6267
*
@@ -248,14 +253,14 @@ const plugin = (opts = {}) => {
248253

249254
// Find the root nesting level
250255
let rootParent = parentRule;
251-
let nestingDepth = 0;
256+
let isSingleLevel = true;
252257
while (rootParent.parent && rootParent.parent.type === 'rule') {
253258
rootParent = rootParent.parent;
254-
nestingDepth++;
259+
isSingleLevel = false;
255260
}
256261

257262
// For single-level nesting (Tailwind case), use simple approach
258-
if (nestingDepth === 0) {
263+
if (isSingleLevel) {
259264
// Add container query inside the parent rule, after the media query
260265
atRule.after(containerQuery);
261266

@@ -335,13 +340,26 @@ const plugin = (opts = {}) => {
335340
// Clone children of root parent (before container query is added)
336341
rootParent.each(node => {
337342
const clonedNode = node.clone();
338-
// Mark any media queries as processed
343+
344+
// Remove media queries that are NOT the current one being processed
345+
clonedNode.walkAtRules('media', (mediaRule) => {
346+
// Keep the current media query we're processing, remove others
347+
if (mediaRule !== atRule && !isSameMediaQuery(mediaRule, atRule)) {
348+
mediaRule.remove();
349+
} else {
350+
mediaRule[processed] = true;
351+
}
352+
});
353+
354+
// If this node itself is a media query
355+
// and not the one we're processing, skip it
339356
if (clonedNode.type === 'atrule' && clonedNode.name === 'media') {
357+
if (!isSameMediaQuery(clonedNode, atRule)) {
358+
return; // Skip appending
359+
}
340360
clonedNode[processed] = true;
341361
}
342-
clonedNode.walkAtRules('media', (mediaRule) => {
343-
mediaRule[processed] = true;
344-
});
362+
345363
conditionalRule.append(clonedNode);
346364
});
347365

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "npm run eslint && npm run mocha",
88
"mocha": "mocha",
9-
"eslint": "eslint --fix --ext .js,.vue ."
9+
"eslint": "eslint --ext .js,.vue ."
1010
},
1111
"author": "Apostrophe Technologies, Inc.",
1212
"license": "MIT",

test/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,6 @@ body[data-breakpoint-preview-mode] {
684684
await run(plugin, input, output, opts);
685685
});
686686

687-
// This test should pass, at least approximately
688-
// to show not selector is added at the root parent level
689687
it('should handle deeply nested media queries', async () => {
690688
const input = `
691689
.foo {
@@ -737,7 +735,6 @@ body[data-breakpoint-preview-mode] {
737735
}
738736
}
739737
}`;
740-
741738
await run(plugin, input, output, opts);
742739
});
743740
});

0 commit comments

Comments
 (0)