Skip to content

fix: bust persisted query cache on deploy - #2058

Open
alanpeixinho wants to merge 1 commit into
kernelci:mainfrom
profusion:fix/frontend-stale-cache
Open

fix: bust persisted query cache on deploy#2058
alanpeixinho wants to merge 1 commit into
kernelci:mainfrom
profusion:fix/frontend-stale-cache

Conversation

@alanpeixinho

Copy link
Copy Markdown
Contributor

What it is

Fixes /tree crashing with Cannot read properties of undefined (reading 'map') when a persisted React Query cache holds an origins payload without checkout_origins / test_origins (#2048).

  • OriginSelect treats missing origin lists as [] so .map cannot throw.
  • Persist cache is versioned with VITE_CACHE_BUSTER (dashboard version, or build-<timestamp> if empty) so a new deploy drops stale blobs.

How to test

Dev persist uses sessionStorage (prod: localStorage). Recover with sessionStorage.clear() then reload.

  1. Open /tree and confirm the origin dropdown works.
  2. Seed a mismatched origins shape and reload:
sessionStorage.setItem('REACT_QUERY_OFFLINE_CACHE', JSON.stringify({
buster: '', timestamp: Date.now(),
clientState: { mutations: [], queries: [{
  queryKey: ['origins'], queryHash: '["origins"]',
  state: { data: ['maestro'], dataUpdatedAt: Date.now(), status: 'success', fetchStatus: 'idle' },
}]},
}));
location.reload();

Expect: no “Something went wrong!”; origins refetch; dropdown populated.
3. Confirm stored buster matches the side-menu version (or build-… if no version).
4. Reload without editing the cache: same buster → hydrates, no crash.

Closes #2048

- Guard pageOrigins so a mismatched origins shape cannot crash /tree
- Version the persist buster so stale cache blobs are dropped on deploy

Closes kernelci#2048
@alanpeixinho

Copy link
Copy Markdown
Contributor Author

Leaving here so it is documented, we had some discussion on calls about solving this by using local memory for cache or sessionStorage. However there are a few drawbacks there.

  • local memory: clears cache at every refresh of the page, being somewhat aggressive when invalidating cache.
  • session storage: refresh would keep the cache, but it would not solve the bug. If a deploy was to change any response schema, the user would still face the same error, requiring them to close and reopen the page on the browser. It means even using sessionStorage, busting stale cache would still be needed.
    Considering this I believe it would be better to keep using localStorage (as it is right now), and just include the stale cache bust.
    cc: @felipebergamin

@felipebergamin

Copy link
Copy Markdown
Member

I made a comment about the sessionStorage then I saw your comment about it. Ok

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.

Listing page crashes with "Cannot read properties of undefined (reading 'map')"

2 participants