Skip to content

Refetch CSS bodies missing from the HAR#150

Merged
marcusosterberg merged 2 commits into
mainfrom
fix/refetch-missing-css-bodies
Jun 12, 2026
Merged

Refetch CSS bodies missing from the HAR#150
marcusosterberg merged 2 commits into
mainfrom
fix/refetch-missing-css-bodies

Conversation

@marcusosterberg

@marcusosterberg marcusosterberg commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Test 27 (TEST_LINT_CSS) concatenates all CSS from the HAR and lints it with stylelint. The no-unknown-custom-properties rule resolves var(--x) only against custom-property definitions present in the linted CSS.

When a stylesheet that defines custom properties is served from cache, returns 304 Not Modified, or is recorded with an empty body, its HAR entry has no response.content.text/size and is dropped in harAnalyzer.js. Every var() referencing those properties in the stylesheets that were captured is then falsely reported as "Unknown custom property"CSS, Disallow unknown custom properties (fel).

Surfaced as a false positive on https://tillvaxtverket.se: filterable-list.css / dark-mode.css consume --lp-* design tokens defined in variables.css; when the defining files come back bodyless, all those references look undefined.

Fix

Detect bodyless CSS entries (by mime type or .css URL) and refetch their content over HTTP before linting. Refetches run in parallel with a 10s timeout each; failures (network error, timeout, non-OK, empty body) are ignored so a single unreachable file never fails the whole test.

Verification

Built a HAR from the real tillvaxtverket.se CSS with the definition files served bodyless (304 / size 0) and ran the actual HarAnalyzer:

active no-unknown-custom-properties issues CSS files linted
Before 74 (false positives) 1
After 0 49 (48 refetched)

When every stylesheet has a body, output is unchanged.

Known limitation

Custom properties defined purely at runtime via JS (el.style.setProperty('--x', …)) still can't be resolved by static linting — out of scope here.

Custom properties are resolved by stylelint's no-unknown-custom-properties
rule only against definitions present in the linted CSS. When a stylesheet
that defines custom properties is served from cache, returns 304 Not
Modified, or is recorded with an empty body, its HAR entry has no content
and was silently dropped. Every var() referencing those properties in the
stylesheets that *were* captured was then falsely reported as "Unknown
custom property".

Detect bodyless CSS entries (by mime type or .css URL) and refetch their
content over HTTP before linting. Failures (network error, timeout, non-OK,
empty body) are ignored so a single unreachable file never fails the test.
The refetch logic uses fetch, AbortController, setTimeout and clearTimeout.
The flat eslint config lists allowed globals explicitly, so add these four
to stop no-undef from failing CI lint.
@marcusosterberg marcusosterberg merged commit fe67aa2 into main Jun 12, 2026
1 check passed
@marcusosterberg marcusosterberg deleted the fix/refetch-missing-css-bodies branch June 12, 2026 14:25
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