birkir / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
137 stars 75 forks source link

Preview path incorrectly created during Gatsby build process #218

Open hs737 opened 4 years ago

hs737 commented 4 years ago

When running gatsby build, one of the page creations is sending a data object of null. I checked to see if this was by design, and I believe it's not. This is related to preview pages. I've turned off previews, but this page is still created. I'm able to prevent the error by ignoring the null case, but that doesn't explain why this is happening. Also, this issue does not happen in gatsby develop.

If the config says, previews: false, then why would the plugin still try to generate a previews path?

gatsby-config.js:

{
    resolve: "gatsby-source-prismic-graphql",
    options: {
        repositoryName: `${process.env.PRISMICIO_REPO_NAME}`, // (required)
        accessToken: `${process.env.PRISMICIO_API_KEY}`, // (optional)
        defaultLang: "en-us", // optional, but recommended
        previews: false, // (optional, default: false)
        pages: [
            {
                type: "Blog_post",
                match: "/blog/:uid",
                path: "/blog",
                component: require.resolve(
                    "./src/components/blog-post.tsx"
                ),
            },
        ],
    },
},

When looking at the output generated by "./src/components/blog-post.tsx" during gatsby build, I see that my react code runs into a null case on the first-page creation. All subsequent page creations seem to run correctly, that too for content that I expect. Also, why isn't this issue occurring for gatsby develop?

Here are the props for the page creation that is returning an odd data object.

{
    "path": "/*",
    "*": "preview/blog_post",      // <-- Why I suspect this is related to previews
    "uri": "/",
    "location": {
        "pathname": "/preview/blog_post",
        "search": "",
        "hash": ""
    },
    "data": {
        "prismic": {
            "blog_post": null      // <-- This isn't null for my expected content
        }
    },
    "pageContext": {
        "rootQuery": null,
        "id": "",
        "uid": "",
        "lang": "en-us",
        "paginationPreviousUid": "",
        "paginationPreviousLang": "",
        "paginationNextUid": "",
        "paginationNextLang": ""
    },
    "pathContext": {
        "rootQuery": null,
        "id": "",
        "uid": "",
        "lang": "en-us",
        "paginationPreviousUid": "",
        "paginationPreviousLang": "",
        "paginationNextUid": "",
        "paginationNextLang": ""
    }
}

This might be similar to https://github.com/birkir/gatsby-source-prismic-graphql/issues/211. I created a separate issue in case the root causes are different.

As a side, I also tried to debug this myself using VSCode and breakpoints. I'm a little newer to debugging Gatsby plugins, so I wasn't successful. Any suggestions on how I could see the logs/execution of the plugin would be appreciated!

necheporenko commented 4 years ago

Yeah, the same issue with previews: false.

It's really strange that when I created a simple blog project, I met so many bugs (#217, #196, and now this).