-
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
fix(gatsby): fix not focusing router wrapper after navigation #13197
Conversation
@@ -33,3 +33,7 @@ Cypress.Commands.add(`shouldNotMatchScrollPosition`, id => | |||
expect(scrollPosition).not.to.be.closeTo(storedScrollPositions[id], 100) | |||
}) | |||
) | |||
|
|||
Cypress.Commands.add(`assertRouterWrapperFocus`, () => |
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.
This is dope! 👍
const target = | ||
stage === `build-html` || stage === `develop-html` ? `node` : `web` | ||
if (target === `web`) { | ||
// force to use es modules when importing internals of @reach.router |
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.
Should we open an issue on @reach/router to make any changes?
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.
We do import internal match
function (to match those parameterized / wildcarderded paths like /app/:someParam
or /app/*
). If @reach/router
exported that from entry point, we wouldn't need this part, but I'm not sure if Ryan would really want that - as this is lower level function. Worth asking at least ;)
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.
@pieh are you sure we need this? https://github.com/reach/router/blob/master/package.json#L6 should take care of it.
Nvm I see what you did there, it's because we require @reach/router/lib/utils
finally got unblocked on this, next step here is to adjust |
dangerouslySetInnerHTML={{ __html: `` }} | ||
suppressHydrationWarning | ||
/> | ||
) |
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.
@davidbailey00 I would like sanity check here:
this seems to do similar thing (preventing react from cleaning up ___gatsby
div) and it works in more scenarios than throwing (in case we throw before any parent component "renders" any DOM element, react will wipe ___gatsby
div). It seems like we were "lucky" with this, because
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.
this means we will do a full client rehydration if something goes wrong, right? maybe add a comment about it?
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.
It's partial hydration - things above the actual page will be hydrated - so if users use wrapRootElement
/wrapPageElement
or gatsby-plugin-layout
those will be actually hydrated, but the content of the page itself (in case template chunk or query results can't be loaded) won't be trully hydrated, but content from static html will be there
This is a neat trick that you can do when using:
<div
dangerouslySetInnerHTML={{ __html: `` }}
suppressHydrationWarning
/>
during hydration, as it won't try to actually change DOM nodes under it.
But yeah, I should add more context there for sure
so the fix is actually bringing all routes under the as separate pages? This way Reach router knows about all paths and can do its magic tricks? |
We still have one route, but it's dynamic - see edit: |
navigating from and to 404 doesn't focus router wrapper correctly. This is because 404 in development is special case (see notes before skipped e2e-tests/development-runtime accessibility tests). This can be fixed but require a lot of changes which would be out of scope of this PR and would potentially make it harder to merge page manifest changes, so for now lets ship fixes that are already here.
This should be ready to review. Here's demo with voiceover for production build https://www.dropbox.com/s/tbrt2uczih2jolk/Kapture%202019-05-18%20at%2017.21.45.mp4?dl=0 - page content is being announced properly (I think). To live check it, you can use for example https://deploy-preview-13197--using-remark.netlify.com/ which is build with changes from this PR Notes:
|
Merge conflicts after |
@@ -7,7 +7,7 @@ const NotFound = () => <h1>Not Found in App</h1> | |||
|
|||
const AppPage = () => ( | |||
<Router> | |||
<App path="/paths/app" /> |
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.
Sweet!
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.
🌮🌮🌮
Published in |
This is work in progress to assert that focus management is working as expected on navigation.
Right now we are misusing
@reach/router
and don't take full advantage of its focus management feature because we have with single catch-all route - which means that this route never change and focus is never triggered.Initially I'll try to push just failing test (to verify correctness), with actual changes following that