I'm having trouble with changes I make to a global syncing to my website that uses that global. I'm reading the global like this, because it's the only way I can find to read a global:
export async function Careers() {
const settings: CareersSetting = await getCachedGlobal("careers-settings", 1)()
return <CareersClient settings={settings} />
}
When I make changes to this global on the Payload admin dashboard, they don't reflect in the CareersClient component even if I restart the site. So I thought the afterChange hook would help with this, and added it to the global:
export const CareersSettings: GlobalConfig = {
slug: "careers-settings",
hooks: {
afterChange: [revalidateGlobalAfterChange],
},
...
where the function looks like this:
export const revalidateGlobalAfterChange: GlobalAfterChangeHook = async ({ global, doc }) => {
revalidateTag(`global_${global.slug}`, "max")
return doc
}
Now if I update the global in the admin panel, nothing happens when I reload the page that hosts the Careers component, but if I update say a default value on one of the fields in the global's source code, even though I'm not using default value anywhere, the hook seems to be called because the Careers component now shows the up to date value I set in the admin page.