-
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
refactor(gatsby): improve EnsureResources #10224
Conversation
I'm bit worried about updating state and then relying on If I understand correctly this is to ensure we only reload during navigation if resources can't be loaded and not on initial render (to prevent infinite reload loop) - if so we can just store variable to see if we are doing initial render to avoid reload if it's initial render? |
Also not really related to this PR, but something that I didn't caught in previous PR - there seems to be edge cases where: const __html = document.getElementById(`___gatsby`).innerHTML
return <div dangerouslySetInnerHTML={{ __html }} /> doesn't work correctly - see https://5c0a7e2267610c06381781cc--vibrant-allen-8e8d7b.netlify.com/page-2/ (I just deleted .json for that page there to trigger this) - part of the page doesn't end up in the DOM - this would be caused by react hydration I would assume - when using this setInnerHTML we put more wrapping divs - one from |
Putting the check in
I've updated it to throw an error rather than using |
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.
Verified once again after updates. Nice one, thanks @davidbailey00!
* master: (33 commits) fix(blog): youfit case study typofix Doc improvements to Visual testing with Storybook guide (gatsbyjs#10436) fix(gatsby-plugin-offline): prevent incorrect revisioning of static file by workbox (gatsbyjs#10416) fix(starters): ttag repo link fix typo in pull request template (gatsbyjs#10454) fix(www) Fix query for plugin links always ?=undefined (gatsbyjs#10453) chore(release): Publish fix(gatsby): fix extracting StaticQuery nested in shorthand fragment (gatsbyjs#10443) fix(www): avoid querying for no-cache=1 (gatsbyjs#10389) fix(gatsby-image): update typescript definitions - properly mark fields as optional (gatsbyjs#10419) refactor(gatsby): improve EnsureResources (gatsbyjs#10224) Fixed minor Typos and grammatical errors (gatsbyjs#9353) docs: add ClinciJS website into showcase (gatsbyjs#10437) docs(babel-preset-gatsby): document --save-dev flag in README (gatsbyjs#10434) fix(docs): Environment Variables Examples (gatsbyjs#10406) chore(release): Publish [gatsby-image] re: fade out base64 on full image load (gatsbyjs#7539) docs(starter-library): add example to starter library (gatsbyjs#10425) docs(gatsby-plugin-offline): specify to not HTTP-cache sw.js (gatsbyjs#10430) fix(docs): prompt => confirm (gatsbyjs#10431) ...
* master: (1037 commits) Update starters.yml (gatsbyjs#10505) chore(release): Publish fix(graphql-skip-limit): fix hasNextPage (gatsbyjs#10504) chore: use cjs instead of esm for consistency (gatsbyjs#10494) feat(gatsby-remark-copy-linked-files): add support for video elements with `src` attribute (gatsbyjs#10395) typofix (gatsbyjs#10488) Add kobit.in to showcase (gatsbyjs#10496) fix(docs): window.reload => window.location.reload (gatsbyjs#10459) feat(www): add unbird feedback component to starter lib (gatsbyjs#10450) fix(blog): youfit case study typofix Doc improvements to Visual testing with Storybook guide (gatsbyjs#10436) fix(gatsby-plugin-offline): prevent incorrect revisioning of static file by workbox (gatsbyjs#10416) fix(starters): ttag repo link fix typo in pull request template (gatsbyjs#10454) fix(www) Fix query for plugin links always ?=undefined (gatsbyjs#10453) chore(release): Publish fix(gatsby): fix extracting StaticQuery nested in shorthand fragment (gatsbyjs#10443) fix(www): avoid querying for no-cache=1 (gatsbyjs#10389) fix(gatsby-image): update typescript definitions - properly mark fields as optional (gatsbyjs#10419) refactor(gatsby): improve EnsureResources (gatsbyjs#10224) ...
I was looking into the changes in this pull request for #10534 and it looks like throwing an error when the resource is not found results in 404 page not being displayed. @davidbailey00 : Can you elaborate on the gain we get (prevent hydration) by throwing an error? Just trying to understand it. |
@apvarun By throwing an error, we prevent React from rendering a blank page. Pages are server-rendered, so if we prevent React rendering then we will still see the page as rendered by the server, which is better than it being blank. |
I think we should not do this in dev environment as the errors get displayed on the screen for debugging. This prevents the gatsby's default page that lists all the existing routes from not displaying during development. |
- `getDerivedStateFromProps` - Remove unused parameter `pageResources` - Return even if we don't have resources, to allow detecting them later - Remove `componentDidUpdate` and move some of its contents into new `retryResources` - Throw an error on initial render only upon missing resources - otherwise just don't update the component, and remove the function `shouldRenderStaticHTML` - Note: this may need updating in the future - React docs say `shouldComponentUpdate` is only for performance purposes and may not prevent rendering in future versions - Add a new function for detecting if we have resources which works for production and develop
getDerivedStateFromProps
pageResources
componentDidUpdate
and move some of its contents into newretryResources
shouldRenderStaticHTML
shouldComponentUpdate
is only for performance purposes and may not prevent rendering in future versions