The save works and the page keeps showing the old value until I hard refresh, what am I supposed to be invalidating?
A form that updates a record. The action runs, the database is updated, no errors anywhere.
The page still shows the previous value. Navigating away and back shows the old value too. A hard refresh shows the new one.
I have tried adding a call to revalidate the path, which sometimes works and sometimes does not, and I cannot see the pattern. I have also seen suggestions to refresh the router, which also sometimes works.
What I am missing is a model of what is actually cached and which of these clears which. At the moment I am adding all of them and hoping, which is clearly not right.
@tags_over_paths · 3w ago
The practical fix that ends the guessing: tag the data at the fetch, invalidate the tag in the action.
Paths are the fragile approach because you have to know every route that displays a piece of data, and keep that list correct forever. Add a dashboard that shows the same record and you now have a second path to remember. Nobody remembers.
With tags, the fetch that loads a record declares what it is, and the action that changes that record invalidates that name. Every page using it updates, and adding a new page requires nothing.
A convention that works well:
The rule I follow: if you find yourself invalidating three paths in one action, you wanted a tag.
Two details:
Tag at the fetch, not at the page. The tag belongs to the data, which is the thing that changed.
Invalidate after the write succeeds, not before, and not in a branch that can be skipped. A surprising number of these bugs are an early return that skips the invalidation on one code path, which produces exactly your intermittent behaviour.
Reply
Report