Skip to content

fix: keep css_data() stylesheets within vue_asset_max_bytes without a cache - #386

Merged
JuroOravec merged 1 commit into
mainfrom
fix/css-data-bounded-store
Oct 25, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/css-data-bounded-store

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #154. This is the second half; #366 was the first.

What changes

Without a configured cache, every distinct css_data() result used to be written to the engine's default in-memory cache, which never drops anything. Values that change per request, such as a per-user color, grew the process for its whole life.

As the maintainer decided in #154 (keep these stylesheets in the bounded per-process store):

  • Without a configured cache: css_data() stylesheets go into the same per-process store as the compiled Vue assets (_LocalAssets in _vue/events.py). They share its vue_asset_max_bytes byte limit, and the ones used longest ago are dropped first.
  • With a configured cache: nothing changes. Each render compares the stored stylesheet and writes it when it differs, and reads go to the backend.

How a page keeps its own stylesheets:

  • hold_page_assets(citry, render, *, publish_css_data=True) is new. It keeps every file the page publishes from being dropped until the block ends, and on entry it publishes the render's css_data() stylesheets (publish_css_data_stylesheets in emission.py).
  • serialize.py enters it before the Vue preparation and the extensions' on_serialize. Preparing an event response enters it too, and so does a page serialized inside another page's on_serialize.
  • So the Vue preparation, the dependencies step's inline read, and the browser's later fetch of a /cache/<class>.<hash>.css link all find the stylesheet.
  • Pages rendered with deps_strategy="ignore" publish nothing.

Other changes:

  • A replayed render no longer writes its stylesheet to the default cache. The page publishes it when it is written.
  • _RENDER_PUBLISHES is now a dict. _enforce_limit returns before walking the store when nothing is over the limit or nothing can be dropped. Writing a page with 8,000 distinct stylesheets takes about 0.12 s, the same as before this change, also with a 1-byte limit.
  • The "digest collision" message names its asset kind in full.

Docs

  • The vue_asset_max_bytes docstring, the cache.py and scripts.py module docstrings, docs_site/content/performance/cache-backends.md ("Limit asset memory"), docs_site/content/advanced/web-frameworks.md ("Share the cache") and docs/design/dependencies.md (sections 4.2 and 10.1) now say that the limit covers these stylesheets.
  • The CHANGELOG line is under Unreleased > Fixes, with the remedy for a page that loses its styles: raise the limit or configure a cache.

Left as it is: Citry.clear() doesn't clear this process's store. That matches how it treats the Vue assets, and pages that are already open keep their files.

Tests

New, in tests/test_vue_asset_memory.py:

  • the store stays within the limit under 200 distinct values;
  • a static page keeps its stylesheets while other renders publish;
  • a Vue page under a 1-byte limit links and serves both of its stylesheets;
  • a Vue page serialized after other renders still has its stylesheet;
  • an event response publishes its stylesheets;
  • a Vue page replayed from the render cache still links its stylesheet;
  • a page serialized inside another page's on_serialize;
  • a configured cache receives every stylesheet and keeps no local copy.

New, in tests/test_ext_cache_component.py: a cache hit without a configured cache keeps its stylesheet in memory only.

Edited: test_cache_hit_repairs_an_evicted_dependency_variable_stylesheet now uses a configured InMemoryCache. It checks that a replay writes the stylesheet back to the backend, and that write now happens only when a cache is configured.

Two of the new tests fail on main: the byte-limit test and the replay test. The others pass on main because main keeps every stylesheet in a cache that never drops anything. They guard the new limit: each one fails against an earlier draft of this change that dropped a page's own stylesheets.

Evidence (local)

  • Full citry and citry_ui suite (-m "not e2e") on origin/main 61ce8af: 9,762 passed, none failed.
  • uv lock, ruff check, ruff format, mypy (also with --platform linux), the protocol phases and the validators pass.
  • This change touches no JavaScript, so the citry-client and events-protocol JS phases didn't run locally.

PR CI runs the cargo phases and the full matrix.

🤖 Generated with Claude Code

@JuroOravec
JuroOravec force-pushed the fix/css-data-bounded-store branch from cbdb67f to 432e3fb Compare October 25, 2026 09:41
… cache

Without a configured cache, every distinct css_data() result was written
to the engine's default in-memory cache, which never drops anything, so
values that change per request grew the process for its whole life.

These stylesheets now live in the same per-process store as the compiled
Vue assets and share its byte limit, which drops the ones used longest
ago. A page publishes its stylesheets as it starts being written, while
its Vue files are also protected from being dropped, so the Vue
preparation, the dependencies step, an event response and a page
serialized inside another one all find them, and the browser can fetch
each one the page links. Inlining reads them from that store. A replayed
render no longer writes its stylesheet to the default cache. With a
configured cache, nothing changes: each render compares the stored
stylesheet and writes it when it differs, and reads go to the backend.

Fixes #154

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the fix/css-data-bounded-store branch from 432e3fb to ee5cb55 Compare October 25, 2026 09:44
@JuroOravec
JuroOravec merged commit 05b95e7 into main Oct 25, 2026
4 of 27 checks passed
@JuroOravec
JuroOravec deleted the fix/css-data-bounded-store branch October 25, 2026 09:46
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.

Dependencies extension: per-render cache round trips and unbounded default-cache growth

1 participant