question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getResourceFromContext returns null for dynamic page generation

See original GitHub issue

Hi

I have the following file pages/[LB].tsx

I want to fetch a page that has the layout builder many blocks inside of it.

here is the code

import Badges from "@/components/Home-page/badges";
import { DrupalClient, DrupalNode } from "next-drupal";

import { Fragment } from "react";

const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL);

export default function LB(props){
    console.log('props.node: ', props);

    return (
        <Fragment>
            <h1>Tesing dynamique LB pages rendering.</h1>
        </Fragment>
    );
}

export async function getStaticPaths(context) {

    console.log('context: ', context);

    return {
      paths: [
            {
                params: {
                    LB: await drupal.getStaticPathsFromContext("node--page", context) + ''
                }
            }
        ],
      fallback: 'blocking',
    }
}

export async function getStaticProps(context){

    const node = await drupal.getResourceFromContext<DrupalNode>("node--page", context);

    return {
        props: {
            node,
        },
    };
}

what it returs:

props: {
    "node": null
}

Thanks a lot.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
shadcncommented, Jul 8, 2022

You don’t need the params part. This is handled for you.

export async function getStaticPaths(context) {
  return {
    paths: await drupal.getStaticPathsFromContext(
      ["node--page"],
      context
    ),
    fallback: false,
  }
}

export async function getStaticProps(context) {
  const path = await drupal.translatePathFromContext(context)

  const node = await drupal.getResourceFromContext(path, context)

  return {
    props: {
      node,
    },
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

getResourceFromContext returns null for dynamic page ...
Hi. I have the following file pages/[LB].tsx. I want to fetch a page that has the layout builder many blocks inside of it....
Read more >
Building Pages - Next.js for Drupal
How to build pages using JSON:API resources from Drupal. ... You can use Next.js dynamic route to build static pages for Drupal entity...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found