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

fix(gatsby): reevaluate page query when page context is modified #15404

Merged
merged 1 commit into from
Aug 8, 2019
Merged

fix(gatsby): reevaluate page query when page context is modified #15404

merged 1 commit into from
Aug 8, 2019

Conversation

RomanHotsiy
Copy link
Contributor

@RomanHotsiy RomanHotsiy commented Jul 4, 2019

Description

When page context is updated by createPage the path is not marked as dirty and page query is not reevaluated resulting in the page not updating in develop mode.

It was already fixed by my in #11048 but it appeared again in v2.2.11 because of refactoring by @KyleAMathews in 91086d4

I added a basic test, but I'm not sure how to write a test to prevent this kind of regression in the future. If anyone has any ideas I would be happy to add a test.

Related Issues

Related to #6097, May be related to #11691

@RomanHotsiy RomanHotsiy requested a review from a team as a code owner July 4, 2019 12:30
@RomanHotsiy RomanHotsiy changed the title fix: reevaluate page query when page context is modified fix(regression): reevaluate page query when page context is modified Jul 4, 2019
RomanHotsiy added a commit to Redocly/gatsby-dist that referenced this pull request Jul 4, 2019
@wardpeet wardpeet changed the title fix(regression): reevaluate page query when page context is modified fix(gatsby): reevaluate page query when page context is modified Jul 4, 2019
@RomanHotsiy
Copy link
Contributor Author

Ping @pieh (you reviewed the previous PR)

@pieh
Copy link
Contributor

pieh commented Jul 8, 2019

Right. There is problem with this that I'm not sure if I noted in previous implementation.

This will work only when context is modified while gatsby develop is running. It won't catch cases of context changes between builds as we don't persist pages created by previous builds right now

@RomanHotsiy
Copy link
Contributor Author

RomanHotsiy commented Jul 8, 2019

@pieh, I think that was fixed here:

const contextModified =
!!oldPage && !_.isEqual(oldPage.context, internalPage.context)

@pieh
Copy link
Contributor

pieh commented Jul 8, 2019

This is what I actually meant. oldPage will be there only when page is updated while gatsby develop is running. It won't catch context changes if you change your content that would cause context to change when gatsby develop is not running (because we don't persist pages data)

@RomanHotsiy
Copy link
Contributor Author

@pieh thanks for clarification!

It won't catch cases of context changes between builds as we don't persist pages created by previous builds right now

Oh, I see. I just verified that this issue happens between builds:

  • I run gatsby build
  • I change somehow page context
  • I run gatsby build and page is not updated since last time

That's a more severe issue... I don't know how to fix it as part of this PR though. Persisting page data is a separate bigger PR.

I believe we can't assume context to be changed every time when oldPage is not there as it may hurt performance. Am I right?

I believe this PR can be merged and a separate issue should be open for "between-builds" context changes. I will be able to work on this fix.

@RomanHotsiy
Copy link
Contributor Author

Sorry to bother you @pieh... but this is a severe issue: build may produce wrong results without the user noticing it.

Could you at least let me know what is your plan on this? Won't you merge this PR without a complete fix? Should I start working on a complete fix?

Thanks in advance.

@pieh
Copy link
Contributor

pieh commented Jul 11, 2019

That's a more severe issue... I don't know how to fix it as part of this PR though. Persisting page data is a separate bigger PR.

I believe we can't assume context to be changed every time when oldPage is not there as it may hurt performance. Am I right?

I believe this PR can be merged and a separate issue should be open for "between-builds" context changes. I will be able to work on this fix.

Yeah, this is bigger issue. The fix might be tiny (i.e. just persist pages redux namespace) - but there is a lot of things to consider here, as right now Gatsby operates under assumption that when it bootstraps pages are empty.

Could you at least let me know what is your plan on this? Won't you merge this PR without a complete fix? Should I start working on a complete fix?

I think it makes sense to merge this in general, but I didn't have yet time to thoroughly review and see if it can potentially cause some regressions.

@pieh pieh self-assigned this Jul 12, 2019
@RomanHotsiy
Copy link
Contributor Author

After some using in production, I noticed a severe performance issue with my changes: instead of rerunning only specific page query it was rerunning all page queries of a specific component.
I now fixed that and force-pushed changes.

@pieh any chance to get it merged soon?

Copy link
Contributor

@sidharthachatterjee sidharthachatterjee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RomanHotsiy This seems like a valuable fix. Tested and verified locally!

I've documented the issue for gatsby build in #16477

Let's go ahead and publish this for now! Thank you 🥇

@sidharthachatterjee sidharthachatterjee merged commit ddddc68 into gatsbyjs:master Aug 8, 2019
@sidharthachatterjee
Copy link
Contributor

Published in gatsby@2.13.54

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.

3 participants