Ask questionscontextModified is not properly re-evaluated if pages are deleted & created


In logic was added to re-evaluate page query when page context was changed. However, this doesn't work in all cases: sometimes pageContext change and there's no way to retrigger a change

This is the code that re-evaluates if page context have changed:

But when we try to replace pages hooking into createPage, following this documentation

with some logic like this one:

exports.onCreatePage = ({ page, actions }) => {
  const { createPage, deletePage } = actions

  if ( {
    // You can access the variable "house" in your page queries now
      context: {,
        house: `Gryffindor`,

and when using gatsby develop, after hitting the __refresh data endpoint, if the conditions when the page gets replaced change, the contextModified logic doesn't work, because after "deleting" the original page, the condition const contextModified = !!oldPage && !_.isEqual(oldPage.context, internalPage.context) evaluates to false (oldPage does not exist)..

Steps to reproduce

  • Gatsby develop with is false
  • Render page
  • Change remote data source so becomes true
  • Hit the __refresh endpoint
  • Render the page

Expected result

Replaced page is rendered with the new context

Actual result

Replaced page with the original context


Answer questions pieh

You are right. I just wonder how we could fix that... deletePage has immediate effect so our store removes that completely and when we recreate it, there's nothing to compare.

I do wonder if we could figure out "entry" createPage action call to grab oldPage from it, run all of the onCreatePage cascade and then compare after everything finished.

Github User Rank List