Skip to content

Commit 53e18e3

Browse files
committed
test: add test case for shared dependency with global CSS (issue #9278)
This test validates the scenario from issue #9278 where two async chunks (blue.js and black.js) share a common dependency (make-text.js), and both import global CSS (hotpink.css) before their module CSS files. The test ensures that module CSS correctly takes precedence over global CSS in the cascade order, matching the behavior of build mode. Addresses feedback from @IanVS
1 parent 84f1e2d commit 53e18e3

File tree

8 files changed

+40
-0
lines changed

8 files changed

+40
-0
lines changed

playground/css/__tests__/tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,19 @@ export const tests = (isLightningCSS: boolean) => {
521521
await expect.poll(() => getBgColor('.diamond-test')).toBe('yellow')
522522
})
523523

524+
// Test for issue #9278: Shared function with global CSS before module CSS
525+
test('async css order with shared dependency and global CSS', async () => {
526+
// Both blue.js and black.js import make-text.js (shared dependency)
527+
// Both import hotpink.css before their own module CSS
528+
// Expected: hotpink.css should load first, then blue/black module CSS should win
529+
// The elements have both .hotpink and their module class
530+
const blueEl = await page.locator('text=async blue').first()
531+
const blackEl = await page.locator('text=async black').first()
532+
533+
await expect.poll(() => getColor(blueEl)).toBe('blue')
534+
await expect.poll(() => getColor(blackEl)).toBe('black')
535+
})
536+
524537
test('@import scss', async () => {
525538
expect(await getColor('.at-import-scss')).toBe('red')
526539
})

playground/css/async/black.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { makeText } from './make-text'
2+
import './hotpink.css'
3+
import styles from './black.module.css'
4+
5+
makeText(styles['black-module'], 'async black')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.black-module {
2+
color: black;
3+
}

playground/css/async/blue.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { makeText } from './make-text'
2+
import './hotpink.css'
3+
import styles from './blue.module.css'
4+
5+
makeText(styles['blue-module'], 'async blue')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.blue-module {
2+
color: blue;
3+
}

playground/css/async/hotpink.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.hotpink {
2+
color: hotpink;
3+
}

playground/css/async/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ import('./async-1.js')
22
import('./async-2.js')
33
import('./async-3.js')
44
import('./diamond.js')
5+
import('./blue.js')
6+
import('./black.js')

playground/css/async/make-text.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function makeText(className, content) {
2+
const div = document.createElement('div')
3+
div.className = `base hotpink ${className}`
4+
document.body.appendChild(div)
5+
div.textContent = `${content} ${getComputedStyle(div).color}`
6+
}

0 commit comments

Comments
 (0)