Skip to content

fix: notice in Safari when a served stylesheet failed to load - #487

Merged
JuroOravec merged 1 commit into
mainfrom
fix/safari-failed-stylesheet
Oct 28, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/safari-failed-stylesheet

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

When a Citry page mounts, the Vue runtime keeps the stylesheet links that the server already wrote into the page, so the page paints with its styles before any script runs. The runtime skips a link that failed. In Chromium and Firefox it can tell: a failed link has no sheet, or its resource timing entry (the browser's record of the download) reports an error status. Safari reports no status in resource timing, and it gives a link whose response failed an empty sheet. So in Safari, a page whose stylesheet failed to load (a 404, or a 503) mounted without its styles, and no error appeared anywhere.

The fix

When no timing entry gives a status and the served link's sheet has no rules, the runtime now loads the same URL again in a probe link whose media matches nothing (media="not all"), so the probe does not change the page's styles. The probe carries the same integrity, crossorigin and nonce as the links the runtime creates, so it uses the same cached copy and passes the same CSP checks.

  • If the probe loads, the runtime keeps the served link, as before.
  • If the probe fails, the runtime removes the served link and requests the stylesheet again, the same way it requests any stylesheet it adds itself. That request reports Citry Vue stylesheet failed to load: <url> if it fails too, as in other browsers. The served link's sheet is empty in this case, so removing it first takes no styles off the page.
  • If the probe gets no answer within 3 seconds, the runtime keeps the served link. That is how the runtime treated every served link before this change, so a stalled request cannot hold the mount.

Cost and error modes

  • A healthy page needs no extra request in any browser: its sheet has rules, so no probe runs.
  • The probe runs only for a sheet with no rules and no status. That happens in Safari when the load failed, for a stylesheet that really contains no rules, and in any browser when the timing entry is missing, for example when the browser's list of download records is full. The browser usually answers the probe from its cache. If it has to fetch again, the mount waits for that request, for at most 3 seconds.
  • In Safari a failed stylesheet now costs two more requests before the error appears: the probe, then the new request, which also acts as a retry.
  • A stylesheet loaded from another origin without a CORS header has rules this page cannot read. The runtime cannot check it, so it keeps treating such a link as loaded.

Tests

In packages/py/citry/tests/e2e/test_asset_cors_e2e.py, an init script deletes PerformanceResourceTiming.prototype.responseStatus, so that Chromium and Firefox take the path the runtime takes in Safari. These tests now run both with and without the status:

  • test_a_served_stylesheet_that_fails_to_load_is_reported: the failed stylesheet is reported and the page does not mount. On main's runtime the without-status case fails, because the page mounts and nothing is reported.
  • test_served_page_paints_with_its_component_styles_before_the_runtime_runs: the runtime keeps the served link, and no other stylesheet link is left behind.
  • test_top_level_page_downloads_each_asset_once: still one request per asset.
  • New, test_a_served_stylesheet_with_no_rules_is_adopted: a stylesheet that holds only a comment loads with no rules, so without a status the probe runs, loads, and the page mounts with exactly one stylesheet link. With the line that removes the probe link taken out of the runtime, the without-status case of this test fails.

Not covered by a test:

  • the 3-second timeout, because Chromium answers the probe from memory, so a test cannot stall it;
  • the guard that skips the new request when the page dropped this stylesheet's entry while the probe was running.

Evidence

  • test_asset_cors_e2e.py: 13 passed on Chromium and 13 on Firefox.
  • WebKit, on the debug/webkit-e2e branch:
    • Run 40626836570 (before this fix): a link to a failed stylesheet gets a sheet with no rules, in both HTML rendering modes (quirks and standards), for a 404 text/plain and a 503 text/css. The timing entry has no responseStatus. A probe link with media="not all" fires error, and fetch() sees the 404.
    • Run 40634878554 (this fix): all 13 tests in test_asset_cors_e2e.py pass on WebKit. That includes the failure being reported, the stylesheet with no rules being adopted, and one request per asset, with and without integrity.
  • pnpm --dir packages/js/citry-client run check passes (241), and runtime.js is rebuilt from client.js.
  • The rest of the citry e2e suite on Chromium passes, apart from 12 tests in test_vue_listener_modifiers_e2e.py and test_vue_slot_props_e2e.py. Those 12 fail the same way on main with my locally installed citry_core, because they need a newer Rust build. PR CI builds it.
  • test_asset_cors_e2e.py runs on WebKit only in the weekly cross-browser job, not in PR CI, so the debug run above is this PR's WebKit evidence.
  • An independent review ran. Its main suggestion, to probe only sheets with no rules, is the design described above.

🤖 Generated with Claude Code

When a Citry page mounts, the Vue runtime keeps the stylesheet links the
server wrote into the page. It skips one that failed: the link has no sheet,
or its resource timing entry reports an error status. Safari reports no
status, and it gives a link whose response failed an empty sheet, so in
Safari a page whose stylesheet failed mounted without its styles and
reported nothing.

When no status is available and the served link's sheet has no rules, the
runtime now loads the same URL again in a link whose media matches nothing.
If that link fails, the runtime requests the stylesheet again as it does in
other browsers, and reports the error if that fails too. The check waits at
most 3 seconds, then keeps the served link, so a stalled request cannot hold
the mount. A healthy page, whose sheet has rules, needs no extra request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the fix/safari-failed-stylesheet branch from 065f322 to 83c384b Compare October 28, 2026 16:13
@JuroOravec
JuroOravec merged commit 5b54065 into main Oct 28, 2026
0 of 30 checks passed
@JuroOravec
JuroOravec deleted the fix/safari-failed-stylesheet branch October 28, 2026 16:14
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