Skip to content

Recently created pages are returning 404 error due memoized function #319

Open
@luizeboli

Description

@luizeboli

Description

Hey Travis 👋🏻, thanks for your amazing work in this boilerplate!

I was giving this starter a try and noticed an unexpected behavior. When creating new pages in Notion after the first build, these new pages return 404 error for a while.

This seems to be related with resolveNotionPage function at line 51, precisely at this memoized getAllPages. The pMemoize cacheKey property will always be the same because it's not bind to the requested page id.

As a result, the canonicalPageMap will be stale.

Steps to reproduce

  1. Do a deploy
  2. Create a new page
  3. Wait NextJs 10 seconds revalidation time
  4. Try to access this new created page
  5. You should be redirect to 404
Screen.Recording.2022-06-03.at.20.41.11.mov

Proposed solution

I didn't find any infos about how p-memoize invalidates it's cache in the docs, so a solution to this may be using expiry-map and the same 10 seconds revalidate time.

const cache = new ExpiryMap(10000)

const getAllPages = pMemoize(getAllPagesImpl, {
  cacheKey: (...args) => JSON.stringify(args),
  cache
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions