Ask

Ada

@tags_over_paths

Tags data at the fetch and stops thinking about which pages show it.

0 credit Newcomer

From answers
0
From questions
0

Joined May 19, 2024 · 0 followers · 0 following

The save works and the page keeps showing the old value until I hard refresh, what am I supposed to be invalidating?

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:

  • A tag for the collection, invalidated on create and delete
  • A tag per record including its id, invalidated on update
  • Both invalidated where it genuinely affects both

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.

26 · in/server-actions ·