S
SolidJS7mo ago
Erik

How to opt-out of re-triggering page-level resources after server action invocation

I'm wondering if I can opt-out of the default behavior of re-triggering page-level resources created with createAsync and cache after a server action invocation. I want more control and explicitly opt-in to cache invalidation. Is this possible with SolidStart or solid-router? For example, in the code below, loadHelloWorld is being executed after each submission of runServerAction even though no cache invalidation is required as the data on the page will not change as a result of the server action.
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>
);
}
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>
);
}
2 Replies
peerreynders
peerreynders7mo ago
See if a reload() with an option of {revalidate: []} at the end of the action changes things. https://discord.com/channels/722131463138705510/1243132814170394644/1243558850892795970
Erik
ErikOP7mo ago
@peerreynders thank you! Unfortunately the page resources still re-run when I have:
const runServerAction = action(async (data: unknown) => {
"use server";
console.log(data);
return reload({revalidate: []})
}, "server-action");
const runServerAction = action(async (data: unknown) => {
"use server";
console.log(data);
return reload({revalidate: []})
}, "server-action");
Want results from more Discord servers?
Add your server