Your development workspace
This app is private. Sign in with your authorized Google account.
For components embedded alongside independently loaded UI, verify computed styles after the actual shared stylesheet is inserted again after the component styles. A passing standalone render does not establish that overrides survive the host page cascade.
| 1 | import { test, expect } from '@playwright/test'; |
| 2 |
|
| 3 | const sharedCss = ".action.primary { background: royalblue; color: white; } .action.primary:hover, .action.primary:focus-visible { background: navy; color: white; }"; |
| 4 | const noticeCss = '.notice .action { background: rgb(17, 17, 17); color: white; }'; |
| 5 |
|
| 6 | test('notice action colors', async ({ page }) => { |
| 7 | await page.setContent(`<style>${sharedCss}</style><style>${noticeCss}</style><div class="host"><section class="notice"><button class="action primary">Continue</button></section></div>`); |
| 8 | await expect(page.getByRole('button', { name: 'Continue' })).toHaveCSS('background-color', 'rgb(17, 17, 17)'); |
| 9 | }); |
Explanation (EN)
Both selectors have equal specificity. This test covers only shared CSS loaded first, so a later copy of shared CSS can break the composed page while the test stays green.
Objašnjenje (HR)
Selektori imaju jednaku specifičnost. Test provjerava samo slučaj kad se zajednički CSS učita prvi, pa kasnija kopija može promijeniti izgled na složenoj stranici dok test i dalje prolazi.
| 1 | import { test, expect } from '@playwright/test'; |
| 2 |
|
| 3 | const sharedCss = ".action.primary { background: royalblue; color: white; } .action.primary:hover, .action.primary:focus-visible { background: navy; color: white; }"; |
| 4 | const noticeCss = `.host .notice .action { background: rgb(17, 17, 17); color: white; } |
| 5 | .host .notice .action:hover, .host .notice .action:focus-visible { background: gold; color: rgb(17, 17, 17); }`; |
| 6 |
|
| 7 | for (const sharedLoadedLater of [false, true]) { |
| 8 | test(`notice colors with later shared CSS: ${sharedLoadedLater}`, async ({ page }) => { |
| 9 | await page.setContent(`<style>${sharedCss}</style><style>${noticeCss}</style><div class="host"><section class="notice"><button class="action primary">Continue</button></section></div>`); |
| 10 | if (sharedLoadedLater) await page.addStyleTag({ content: sharedCss }); |
| 11 | const action = page.getByRole('button', { name: 'Continue' }); |
| 12 | await expect(action).toHaveCSS('background-color', 'rgb(17, 17, 17)'); |
| 13 | await action.hover(); |
| 14 | await expect(action).toHaveCSS('background-color', 'rgb(255, 215, 0)'); |
| 15 | await expect(action).toHaveCSS('color', 'rgb(17, 17, 17)'); |
| 16 | await page.mouse.move(0, 0); |
| 17 | await page.keyboard.press('Tab'); |
| 18 | await expect(action).toBeFocused(); |
| 19 | await expect(action).toHaveCSS('background-color', 'rgb(255, 215, 0)'); |
| 20 | }); |
| 21 | } |
Explanation (EN)
The existing host ancestor gives the intended local override greater specificity. The browser test checks both initial order and a later shared stylesheet copy, including normal, hover and keyboard focus. These strings are synthetic test-owned CSS fixtures. Real component tests should reload the actual imported or emitted shared stylesheet.
Objašnjenje (HR)
Postojeći nadređeni element daje lokalnom pravilu potrebnu specifičnost. Browser test provjerava početni poredak i kasniju kopiju zajedničkog CSS-a, uključujući osnovni izgled, hover i fokus tipkovnicom. Ovdje su stilovi sintetički fixturei testa. Test stvarne komponente treba ponovno učitati stvarni uvezeni ili generirani zajednički CSS.
Activation: implementation or review changes CSS, DOM ownership, a component variant or shared-control styling in an embedded or independently bundled UI. Inspect the rendered DOM, compiled competing selectors, cascade layers and actual host stylesheet insertion order. In a real CSS-capable browser, load the relevant shared stylesheet after the component and check required normal, hover, focus-visible and active states across affected variants and representative viewport sizes. Reuse the real shared CSS rather than copying production declarations into an unrelated mock. For a cascade bug fix, add a focused regression that fails without the override fix, and clean up the injected stylesheet after the test. Selectors, build-managed layers or supported customization tokens may solve the conflict. Prefer the smallest justified override through existing ownership, without adding wrapper markup or blanket important flags. Record untested host conditions before claiming integration readiness.
A documented Shadow DOM boundary, verified deterministic stylesheet deduplication or tested cascade-layer contract can make the extra insertion scenario inapplicable. CSS Modules alone are not such a boundary. Do not increase specificity when the component already uses a supported customization API or already wins under the relevant load orders. Do not add CSS-order tests to changes that cannot affect rendering or style composition.
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).