Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

On-Demand Revalidation Issue with Payload App

default discord avatar
zed0547last year
7

Hi

@805318668556435486



Please don't cross-post questions between channels



Have a look here at how Payload uses hooks to achieve revalidation:

https://github.com/payloadcms/payload/blob/main/templates/website/src/collections/Pages/hooks/revalidatePage.ts

This is how the website template actually handles "Pages" collection pages:

https://github.com/payloadcms/payload/blob/main/templates/website/src/app/(frontend)/%5Bslug%5D/page.tsx
  • default discord avatar
    shuvo0019last year
    @654031862146007055

    Hi, noted on the cross-posting, won’t happen again,

  • default discord avatar
    zed0547last year

    No worries!

  • default discord avatar
    shuvo0019last year

    Hey

    @654031862146007055

    , I have a quick question, would you mind helping me out?



    I'm a bit confused about the behavior of the payload.


    like here this collection is default from payload initialization:



    import type { CollectionConfig } from 'payload'
    
    export const Media: CollectionConfig = {
      slug: 'media',
      access: {
        read: () => true,
      },
      fields: [
        {
          name: 'alt',
          type: 'text',
          required: true,
        },
      ],
      upload: true,
    }

    when i upload and delete anything in this collection then its revalidate auto then why i need to add manual revalidation for my categories collection ?


    .

  • default discord avatar
    zed0547last year

    I have no idea what you mean by revalidate "auto" - when you create a new Media, it has a distinct new ID and a url to reach the resource. There's not really any revalidation. If you wanted to udpate the Media on pages that are using ISR, you would need to trigger a revalidation of those pages, which is what those hooks are for.



    You create a page, it gets "cached" on the server and sent out to clients. Then you want to make an update, but you need to let your server/frontend know that the cache has been invalidated, this is the purpose of those hooks essentially.

  • default discord avatar
    shuvo0019last year

    What’s confusing me is that in my case, I haven’t added any custom revalidation hooks for the Media collection, yet when I upload or delete a media item, the frontend seems to reflect those changes right away.



    On the other hand, for collections like Categories, I have to manually trigger revalidation using hooks to see updates on the frontend.



    Is there a reason for this difference in behavior? Does Payload treat the Media collection differently under the hood, or am I missing something?



    Sorry if my question sounds a bit off, Im still pretty new to how Payload and ISR work together, so I’m trying to wrap my head around everything.

  • default discord avatar
    zed0547last year

    Well, your frontend isn't showing your media collection, it's showing the page where there is a reference to that media collection document



    As for your category, you're probably using calls to that category collection directly



    Are you using a template?

  • default discord avatar
    shuvo0019last year

    No, I'm not using templates, I've initialized the payload in my existing app.



    @654031862146007055

    Thanks for you help now i got it

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.