Skip to content

<c-cache> around an element with $c-tr makes the second render fail to start the Vue app #631

Closed

Description

@JuroOravec

What happens

When <c-cache> wraps an element that has a $c-tr binding, the first render works. A later render that hits the cache writes the first render's binding id into the page, and the server sends the browser no definition for that id. The browser throws, the Vue app fails to start, and the client region is an empty <div>.

In headless Chrome the console shows:

Uncaught TypeError: [Citry] i18n: binding <first-render-id>~i18n-0 is not active.
Uncaught Error: Citry Vue app failed during initialization

Reproduction

import re

from citry import Citry, Component

app = Citry(
    autodiscover=False,
    extensions_defaults={
        "i18n": {"source_locale": "en-US", "locales": ("en-US",)},
    },
)


class Page(Component):
    citry = app
    messages = "loading = Loading"

    def template_data(self, kwargs, slots):
        print("Page id:", self.id)
        return {}

    template = """
    <html><body>
      <c-i18n c-client="True" tag="main">
        <c-cache key="tr-fragment">
          <output $c-tr:loading>{{ tr("loading") }}</output>
        </c-cache>
      </c-i18n>
    </body></html>
    """


for n in (1, 2):
    html = Page().render().serialize()
    ids = re.findall(r'data-citry-i18n-binding="([^"]*)"', html)
    print(f"render {n} binding ids:", ids)
    with open(f"render{n}.html", "w") as file:
        file.write(html)
  1. Run the script. Both renders print the same binding id, although the two Page instances have different ids. The id carries the id of the first Page.
  2. Open render1.html and render2.html in a browser. The first shows "Loading". In the second, <div data-v-app> is empty and the console shows the error above.

In the second render, the manifest's i18n payload (manifest.extensions.i18n.payload.requirements) holds no binding, and preparedData.citryBinding0 holds the stale id.

What I expected

A cache hit gives the binding a fresh id for the new render, and the browser gets a matching definition, so the second render shows "Loading" like the first one and like a page with no <c-cache>.

Which templates fail

I changed the template to find where the problem starts. I checked only a text binding, not an attribute binding such as $c-tr:title.

Template Second render
<c-cache> around the element, in the component that holds <c-i18n> stale id, page fails
<c-cache> around the element, inside a child component of the one that holds <c-i18n> stale id, page fails
<c-cache> around a <div> that holds the element stale id, page fails
<c-cache> around a component whose own template holds the element fresh id, works
no <c-cache> fresh id, works

So the element does not have to be a direct child of <c-cache>. The failing cases have one thing in common: the component whose template contains the $c-tr element is outside the cached part.

Where the code is

This is my reading of the code. I have not tried a fix.

  • packages/py/citry/citry/ext/i18n/bindings.py:166-172: allocate_id builds the id from the id of the component that owns the element. That component's render record holds the binding.
  • packages/py/citry/citry/ext/cache/replay.py:173-188: the cache stores only the components rendered inside the cached part.
  • packages/py/citry/citry/ext/i18n/extension.py:1385-1414: export_render_cache keeps only the records of those components, so the owner's bindings are not stored. stage_render_cache (line 1416) renames only the ids it restored, so the first render's id stays in the replayed HTML and data.
  • packages/js/citry-client/src/citry-i18n-vue.ts:620-631 and :699-702: the browser defines bindings only from the payload, and throws binding <id> is not active for a missing one.

Why the existing tests do not catch it

packages/py/citry/tests/e2e/test_cache_replay_e2e.py:207 and packages/py/citry/tests/test_ext_cache_typed_artifact.py:1628 cache a component with class Cache. There the component that owns the $c-tr element is the cache boundary, so its record is stored and renamed on replay. I found no test that combines <c-cache> with $c-tr.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions