-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(develop): add explicit express handler for page-data requests #27882
Conversation
const pageData = await readPageData( | ||
path.join(store.getState().program.directory, `public`), | ||
page.path | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify - we will actually use the new page data utility here? (i.e. #27939)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the plan. It should look similar as https://github.com/gatsbyjs/gatsby/pull/27939/files#diff-e4535fc084e00493cdf64059b0257b3ba2ee3fe54ec9396daf87158b0679905cL193-R200 part in websocket manager
…d dont rely on express-static
new express handler will try to load the page result if page exists in store so to mimic 404 page not existing we actually need to delete that page
78d3dba
to
ee81ad6
Compare
emitter.on(`DELETE_PAGE`, action => { | ||
if (page404 && action.payload.path === page404.path) { | ||
boundActionCreators.deletePage({ | ||
...page404, | ||
path: PROD_404_PAGE_PATH, | ||
}) | ||
page404 = null | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prod-404
internal plugin is actually also used ingatsby develop
- removing
/404/
page (that this plugin clones into/404.html
) wasn't removing clone which meant that 404 page removals didn't actually removed/404.html
page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about this plugin, just want to understand: why does it hook into onCreatePage
instead of creating its own page? And where do we actually create the source 404
page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so explanation for this plugin - when user creates src/pages/404.js
, the actual path for page is /404/
(that's what gatsby-plugin-page-creator
does) which translated to /404/index.html
when generating .html file - this is fine, but a lot of hosting solutions handle /404.html
as potential default to show 404 page (I think Netlify does this for sure). So we do special case 404 kind of page and create "duplicate" page for it
The src/pages/404.js
is also not only case when we do this - if user creates page programatically in createPages
- this will work too.
Note that this is mostly needed for production builds, but our shared runtime (both dev and prod) also uses /404.html
in multiple places, so the way this plugin works impact both develop and prod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍 Posted a couple of questions - but that's more out of curiousity. Nothing blocking.
emitter.on(`DELETE_PAGE`, action => { | ||
if (page404 && action.payload.path === page404.path) { | ||
boundActionCreators.deletePage({ | ||
...page404, | ||
path: PROD_404_PAGE_PATH, | ||
}) | ||
page404 = null | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about this plugin, just want to understand: why does it hook into onCreatePage
instead of creating its own page? And where do we actually create the source 404
page?
Description
Adds explicit handler and not use
express-static
forpage-data
fetch requests. This allow us to find exact page browser request resources for and will enable triggering query on demand.Side-effect will also be that we won't serve "stale" page-data resources in develop (builds already handle it by deleting files - #26937 )
[ch18448]