Sometimes can't fetch pages with builder.get('page', { userAttributes: { urlPath } })

The system was working perfectly, until suddenly we started getting inconsistent errors on some pages.

This is our code (NextJS):

builder.init(config.BUILDER_API_KEY);

export async function getStaticProps({ params }) {
  const page = await builder
    .get('page', {
      userAttributes: {
        urlPath: '/' + (params?.page?.join('/') || ''),
      },
    })
    .toPromise();

Sometimes it returns undefined, even though the page url is defined well. If we make a very small irrelevant change like change the page name, or just wait a while - then it suddenly works out and returns the page.

For example here:

We have “@builder.io/react”: “^2.1.0”,
But also failed with 3.0.1

Hi @adam, Welcome to Builder.io Forum!

We’re sorry for any inconvenience. We are trying to reproduce the issue and will keep you updated!

@adam, Unfortunately, I’m able to reproduce the issue on my end. Could you please help us with sharing a couple of page URLs where you’re seeing undefined errors or would be great if you can share a screen recording for further investigation?

Thanks,
As I said the problem is inconsistent. I believe it happens with unpublished pages, as I published the latter and it started working.

You can see it here for example:

We get an error TypeError: Cannot read properties of null (reading 'data') - and this is because the page returns as undefined and we access page.data.url

@adam, I opened the shared content which shows Unexpected Error: Something went wrong within the editor. Before proceeding further with debugging, just wanted to confirm if is this because of an undefined value or something else from your end?

Yes it’s because of that. You can open the second link (the preview one) and see the error in the console:

Thanks for confirming. I’m on it and will keep you updated!

1 Like

@adam, We looked into this and made a loom: Loom | Free Screen & Video Recording Software | Loom, please check this out and let me know if I miss on anything!

Hi Garima,
Thanks for investigating. Please see the original message, it fails on page.data.url because the page is not found, which is the source of the problem we are trying to solve.

Actually, I managed to reproduce it in a CodeSandbox.
It’s very strange. If I fetch just the problematic page first (/product), and then another page (/pricing-plan) - both are returned as undefined.
But if I first fetch the pricing page, and then the product page - they are both returned successfully!
This is definitely a problem with the builder/react library. You can see it here:

Could you please share your CodeSandbox link?

Actually I think it’s 2 different bugs:

  1. Product page is not found (main bug that we want to solve)
  2. Calling builder.get in parallel returns the same page for both calls instead of treating them separately

Sure:
https://codesandbox.io/s/zen-cache-9zttq1?file=/src/App.js