How to opt-out of re-triggering page-level resources after server action invocation #1555
-
I'm wondering if I can opt-out of the default behavior of re-triggering page-level resources created with const runServerAction = action(async (data: unknown) => {
"use server";
console.log(data);
}, "server-action");
const loadHelloWorld = cache(async () => {
console.log("Re-run loader")
return "Hello World"
}, "load-home");
export const route = {
load: () => loadHelloWorld,
} satisfies RouteDefinition;
export default function Home() {
const data = createAsync(() => loadHelloWorld());
return (
<main>
<Title>Hello World</Title>
<h1>{data()}</h1>
<form method="post" action={runServerAction}>
<button type="submit">Run server action</button>
</form>
</main>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello, yes this is possible by manually returning a json/redirect/reload object from the actions you don't want to trigger invalidations for. Taken from the docs: const deleteTodo = action(async (formData: FormData) => {
const id = Number(formData.get("id"))
await api.deleteTodo(id)
return json(
{ deleted: id },
{ revalidate: ["getAllTodos", getTodos.key, getTodoByID.keyFor(id)]}
)
//or
return reload({ revalidate: ["getAllTodos", getTodos.key, getTodoByID.keyFor(id)]})
//or
return redirect("/", { revalidate: ["getAllTodos", getTodos.key, getTodoByID.keyFor(id)]})
}) |
Beta Was this translation helpful? Give feedback.
Hello, yes this is possible by manually returning a json/redirect/reload object from the actions you don't want to trigger invalidations for.
In the new docs its explained here: https://docs.solidjs.com/solid-router/reference/data-apis/action#revalidate-specific-cached-keys
Taken from the docs: