Stale data after navigating back to page.

Pending an answer still

I’ve got a data fetching code component that also exposes element actions.
When I first load the page , the data fetch happens as expect and I get latest data.

Then I run element actions to mutate data.

Then, when I navigate away from the page and back, I get stale data.

I assume this is because usePlasmicQueryData function is caching the fetch so it doesn’t run again when I navigate back to the page?

If so, how can I revalidate the cache after mutation?

Here’s a short video showing my issue and I’ll attach the relevant code files to the thread.

I’m running nextjs pages router with Plasmic Loader.

Thanks in advance!

StaffProvider: the data fetching code component




catchall page


Can I ask, is there a reason you’re doing all this via code instead of building it all out in the Plasmic Studio? Seems a little overkill to me.

Good question :slightly_smiling_face:
I’m using supabase for auth and my backend.
I don’t want to use the supabase integration in plasmic for data fetching & mutation because doing so would skip supabase’s main features of an auto-generated API server with heaps of security features etc, and instead it would be no better than using a vanilla postgres database.

Therefore, I tried using the http and graphql integrations to query supabase via it’s auto-generated API server, but the experience was painful.
Therefore, doing data fetching & mutations in code allows me to use supabase’s awesome tooling most effectively because I can write my fetching etc in the javascript code that supabse is designed for. Eventually it will let me do more advanced things if needed like realtime subscriptions, optimistic updates etc.
(I’m making a pretty large app so the effort is worth it)

In terms of using it for auth: I need and want to use supabase auth as my main auth provider, especially since I’m querying & mutating data using native supabase code.
Therefore, I didn’t see much benefit in tacking Plasmic auth on top of Supabase auth and complicating matters, so I’ve been working on getting auth working via code components too.

Open to any thoughts you have, though :slightly_smiling_face: I’m still new to Plasmic

All this code may be a bit over my head to provide any concrete feedback as to code. I’m interested in Supabase auth myself as I consider it for a project.

I’m gonna look into this auto-generated API server see what’s about.

I am curious about the mutations you mention. Do you have an example of mutations that use native supabase code?

Sure thing. Would you like me to show you around what I’ve done so far on a video call? Might be easier

It’s not quite clear to me how and when you’re fetching the data, but I know in Plasmic to get new data, you can invalidate queries which makes them fetch again.

Otherwise I can try to descirbe :slightly_smiling_face:

Appreciate the offer, but no time for video call, doing a bunch of things… just if you happen to have a code example, if not , no worries.

OK I’ll send something through in a sec