Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Preview path incorrectly created during Gatsby build process #218

Open
hs737 opened this issue May 29, 2020 · 1 comment
Open

Preview path incorrectly created during Gatsby build process #218

hs737 opened this issue May 29, 2020 · 1 comment

Comments

@hs737
Copy link

hs737 commented May 29, 2020

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 #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
Copy link

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).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants