next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

getStaticPaths returns a fraction of the items

Open Vacilando opened this issue 9 months ago • 5 comments

Package

next-drupal (NPM package)

Ask the question

Trying to generate all pages in [...slug].tsx statically, implemeted getStaticPaths like this:

export async function getStaticPaths(context): Promise<GetStaticPathsResult> {
  return {
    paths: await drupal.getStaticPathsFromContext("node--value", context),
    fallback: false,
  };
}

The problem is that this fetches 1000 path items, but Drupal contains over 3000 of these kind of nodes.

How can we possibly fetch all of the items here?

Vacilando avatar Mar 27 '25 00:03 Vacilando

@Vacilando This module is configured with a limit of 1,000. While this limit can likely be changed with a patch, it may impact performance. https://github.com/chapter-three/next-drupal/blob/v2.0/modules/next/modules/next_jsonapi/next_jsonapi.services.yml#L2

ksk1kd avatar Mar 27 '25 16:03 ksk1kd

Definitely a good practice to use a reasonable maximum ✓

However, while performance is indeed a consideration, many projects do need to retrieve many (tens of) thousands of node paths to render the nodes statically.

Is there perhaps an option to page through all available nodes to get all paths for a given node type?

Vacilando avatar Mar 27 '25 16:03 Vacilando

@Vacilando Isn't it possible to handle pagination using offset and limit?

const paths = await drupal.getStaticPathsFromContext(RESOURCE_TYPES, context, {
  params: {
    "page[offset]": 1000,
    "page[limit]": 1000,
  }
});

ksk1kd avatar Mar 27 '25 16:03 ksk1kd

@ksk1kd using offset would be an elegant solution indeed. But I don't see page[offset] documented anywhere. Did you try using offset, or have you seen any code using it?

As for page[limit] - that is documented at https://next-drupal.org/guides/page-limit But if I understand it correctly, next_jsonapi.size_max is a hard limit, which cannot be reset using page[limit].

Vacilando avatar Mar 27 '25 17:03 Vacilando

@Vacilando Pagination is documented in the JSON:API documentation. https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/pagination I tested using offset in getStaticPathsFromContext function, and it worked as expected.

ksk1kd avatar Mar 28 '25 15:03 ksk1kd