How to update Theme props on data is revalidation in Next.js with app router? #219
Unanswered
chrishoermann
asked this question in
Q&A
Replies: 2 comments
-
This is probably a Next.js thing anyway, but can you isolate the issue to a minimal, reproducible example on CodeSandbox? |
Beta Was this translation helpful? Give feedback.
0 replies
-
What happens if you do the following when revalidating? import { revalidatePath } from 'next/cache'
revalidatePath('/', 'layout') I am doing something similar to you but I am updating the theme on the client + saving to DB. Client is immediately reading the value from const themeContext = useThemeContext();
const { accentColor, onAccentColorChange } = themeContext;
<input
type="radio"
required
name="accentColor"
value={color}
checked={color === accentColor}
onChange={(event) =>
onAccentColorChange(
event.target.value as ThemeOptions["accentColor"],
)
}
/> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a monorepo with two nextjs (app router) apps and a shared backend that is based upon the plattforms preset from next js. One app is a dashboard app where users can create sites with custom domain or subdomains and which is used to controls the content and the visuals of the site app
revalidation with cache tags works so far by using route handlers in the site app that are called from the backend of the dasboard app.
But one thing that does not work as expected is the revalidation when a users changes the colors of his site on the dashboard.
I use radix theme as a base color provider for my Site app combined with tailwind. As I understand Radix themes uses a Theme Provider that adds html attributes to a div that wrapps the whole application that looks like this:
Here's my layout that feeds the values from the database into the Theme provider:
The fetcher looks like this:
Which calls a trpc endpoint server side
the revalidate site route handler looks like this:
which is called with this fetcher in every endpoint that changes theme data:
Everything is working so far except that the theme data is not updated on every page of the given domain when revalidation is triggered.
For example after reloading the page on
https://mydomain
the theme data looks like this:and on other pages like
https://mydomain/subpage
the theme data still has the old color:Since I call the fetcher
getSiteData
in the root layout I'd expect that all pages that rely on this layout should be invalidated and have the new color on the next pageload. I must admit that I currently don't understand the next js app router caching to its full extend so there may be a high chance that I made some mistakes in my revalidation logic or that I miss some other pieces of the puzzle. Maybe I miss something with theTheme
provider?Since I assume this issue has something to do with caching and server rendering I also tried moving the
Theme
provider to a separate component that is explicitly stated "use client" but this did also not change anythingAny help is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions