Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[source-contentful] node deletions bug #5747

Closed
Khaledgarbaya opened this issue Jun 6, 2018 · 3 comments · Fixed by #5756
Closed

[source-contentful] node deletions bug #5747

Khaledgarbaya opened this issue Jun 6, 2018 · 3 comments · Fixed by #5756
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Khaledgarbaya
Copy link
Contributor

If you hook up your project with a Contentful space that has deleted blog posts, they are still being fetched by GraphQL. It seems like CF doesn't delete the nodes once they are created--they just get returned with null values:

nodes

The issue this presents is in the index page (src/pages/index.js) because the code is looping through each node and creating a div for it (so a user could end up with empty white space on their blog if they have deleted entries--I was able to recreate):

            {posts.map(({ node }) => {
              return (
                <div className="article" key={node.slug}>
                  <ArticlePreview article={node} />
                </div>
              )
            })}

I was looking at this issue with another engineer and the easiest solution we could come up with is to only use nodes that have a valid title. So instead of this:

const posts = get(this, 'props.data.allContentfulBlogPost.edges')

You can filter for only posts that have a title (or any other field):

const allPosts = get(this, 'props.data.allContentfulBlogPost.edges')
const posts = allPosts.filter(post => post.node.title)

Question: Is it expected behavior to have phantom nodes even after posts are deleted? And should I create a PR to filter out these nodes if you agree with my assessment?

@zcei Had a theory

From what I found, there might a bug here, as deleted entries are handled by gatsby-source-contentful.

I haven't worked a lot with the source, but it looks like we're using the (maybe c-prefixed) entity ID to delete a node, while a different format is used to create the node.

@KyleAMathews
Copy link
Contributor

Ooooo that's definitely it! I think I added that deleting code early and then later added the id padding code and forgot to update the deleting code.

@pieh pieh added the type: bug An issue or pull request relating to a bug in Gatsby label Jun 6, 2018
@ryanditjia
Copy link
Contributor

Could this be the same bug? #5348 (comment)

In that comment, I mentioned there being 1036 nodes, close to 70% were nulls.

@axe312ger
Copy link
Collaborator

Opened a PR which should fix this issue :)

pieh pushed a commit that referenced this issue Jun 13, 2018
* fix(contentful): properly delete deleted entries and assets

fixes #5747

* remove duplicate id normalization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants