Skip to content

Prefix Matching

In many great literary works (the House of Atreus, One Hundred Years of Solitude, the Old Testament), a curse is placed not only on the protagonist, but also on their progeny. That’s friggin’ awesome.

Tags work the same way. When you invalidate a tag, all “child” tags are also invalidated.

const tags = defineTags({
user: (id: string) => ['user', id],
userPosts: (id: string) => ['user', id, 'posts'],
userSettings: (id: string) => ['user', id, 'settings'],
});
// Invalidating tags.user('123') also invalidates:
// - ['user', '123'] ← exact match
// - ['user', '123', 'posts'] ← prefix match
// - ['user', '123', 'settings'] ← prefix match

If you only want to invalidate the exact tag:

return {
invalidates: [tags.user(id)],
exact: true, // Only invalidates ['user', '123'], not children
};