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

Check for undefined Value When Deleting Pages #1902

Merged
merged 4 commits into from
Aug 24, 2017
Merged

Check for undefined Value When Deleting Pages #1902

merged 4 commits into from
Aug 24, 2017

Conversation

deniaz
Copy link
Contributor

@deniaz deniaz commented Aug 24, 2017

Hey there!

I wanted to use gatsby-plugin-sitemap but wanted all locs without trailing slashes (our webserver is configured this way as well). I followed your example here to remove trailing slashes in all paths, but unfortunately the build fails with:

error UNHANDLED REJECTION


  TypeError: Cannot read property 'id' of undefined

  - page-query-runner.js:164
    [name]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:164:74

  - Array.reduce

  - page-query-runner.js:160 findDirtyIds
    [name]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:160:18

  - page-query-runner.js:47 _callee$
    [name]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:47:22

  - index.js:400 _callee$
    [name]/[gatsby]/dist/bootstrap/index.js:400:20

This is because emitter listens to the DELETE_PAGE action being triggered here and then calling deleteNode(createPageId(action.payload.path)) (note that one param is passed). deleteNode accepts two arguments; nodeId and node (plus plugin with a default value). Both values, nodeId and node are passed as the action's payload.

Here the emitter listens to DELETE_PAGE actions, and pushes action.node into the queuedDirtyActions array - in my case action.node is undefined.

Later, the pager query runner tries to find dirty IDs here by reading queudDirtyActions - node is still undefined and therefore reading node.id on L112 results in an error.

I'm not convinced that this is the best solution, but honestly, I don't understand the process well enough to decide this. Maybe it makes more sense to pass the node, but I wouldn't know how to find and get the correct one. Or even checking in deleteNode whether node is defined, and only passing it then - the same were the emitter is listening for the DELETE_NODE action.

I hope this all made sense to you! Let me know what you think.

Cheers,
Rob

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 24, 2017

Deploy preview failed.

Built with commit 81e8aec

https://app.netlify.com/sites/using-glamor/deploys/599ef9d1a700c46f2bb7e64d

@KyleAMathews
Copy link
Contributor

Oh hmmm...

I think the right fix would be to also pass in the node in the internal-data-bridge plugin. Lemme just update this PR with that and I'll merge.

Sorry about the breakage and thanks for investigating!

@KyleAMathews KyleAMathews merged commit 71c3596 into gatsbyjs:master Aug 24, 2017
@jlengstorf
Copy link
Contributor

Hiya @deniaz! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

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

Successfully merging this pull request may close these issues.

None yet

3 participants