-
Notifications
You must be signed in to change notification settings - Fork 27.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
Give priority to document.title over h1 when announcing page change #31147
Merged
kodiakhq
merged 3 commits into
vercel:canary
from
KittyGiraudel:document-title-announcer
Nov 8, 2021
Merged
Give priority to document.title over h1 when announcing page change #31147
kodiakhq
merged 3 commits into
vercel:canary
from
KittyGiraudel:document-title-announcer
Nov 8, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KittyGiraudel
requested review from
huozhi,
ijjk,
shuding and
timneutkens
as code owners
November 8, 2021 13:11
shuding
previously approved these changes
Nov 8, 2021
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.
Thanks a lot!
This comment has been minimized.
This comment has been minimized.
@shuding I realized I left a linting error. I just addressed it by rebasing my commit. Sorry about this. 🙇♀️ |
No worries! |
shuding
approved these changes
Nov 8, 2021
Stats from current PRDefault Build (Increase detected
|
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
buildDuration | 19.2s | 18.9s | -230ms |
buildDurationCached | 4s | 3.9s | -62ms |
nodeModulesSize | 332 MB | 332 MB |
Page Load Tests Overall increase ✓
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 3.211 | 3.113 | -0.1 |
/ avg req/sec | 778.57 | 802.97 | +24.4 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.433 | 1.415 | -0.02 |
/error-in-render avg req/sec | 1744.94 | 1766.97 | +22.03 |
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
450.HASH.js gzip | 179 B | 179 B | ✓ |
framework-HASH.js gzip | 42.2 kB | 42.2 kB | ✓ |
main-HASH.js gzip | 28 kB | 28 kB | |
webpack-HASH.js gzip | 1.45 kB | 1.45 kB | ✓ |
Overall change | 71.9 kB | 71.9 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.23 kB | 1.23 kB | ✓ |
_error-HASH.js gzip | 194 B | 194 B | ✓ |
amp-HASH.js gzip | 312 B | 312 B | ✓ |
css-HASH.js gzip | 327 B | 327 B | ✓ |
dynamic-HASH.js gzip | 2.38 kB | 2.38 kB | ✓ |
head-HASH.js gzip | 350 B | 350 B | ✓ |
hooks-HASH.js gzip | 635 B | 635 B | ✓ |
image-HASH.js gzip | 4.44 kB | 4.44 kB | ✓ |
index-HASH.js gzip | 263 B | 263 B | ✓ |
link-HASH.js gzip | 1.87 kB | 1.87 kB | ✓ |
routerDirect..HASH.js gzip | 321 B | 321 B | ✓ |
script-HASH.js gzip | 383 B | 383 B | ✓ |
withRouter-HASH.js gzip | 318 B | 318 B | ✓ |
334f979574ae..6f4.css gzip | 106 B | 106 B | ✓ |
Overall change | 13.1 kB | 13.1 kB | ✓ |
Client Build Manifests
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
_buildManifest.js gzip | 459 B | 459 B | ✓ |
Overall change | 459 B | 459 B | ✓ |
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
index.html gzip | 522 B | 521 B | -1 B |
link.html gzip | 535 B | 533 B | -2 B |
withRouter.html gzip | 515 B | 515 B | ✓ |
Overall change | 1.57 kB | 1.57 kB | -3 B |
Diffs
Diff for main-HASH.js
@@ -1842,14 +1842,17 @@
}
function RouteAnnouncer() {
var asPath = (0, _router).useRouter().asPath;
- var ref = _slicedToArray(_react.default.useState(""), 2),
- routeAnnouncement = ref[0],
- setRouteAnnouncement = ref[1];
- // Only announce the path change, but not for the first load because screen reader will do that automatically.
+ var ref1 = _slicedToArray(_react.default.useState(""), 2),
+ routeAnnouncement = ref1[0],
+ setRouteAnnouncement = ref1[1];
+ // Only announce the path change, but not for the first load because screen
+ // reader will do that automatically.
var initialPathLoaded = _react.default.useRef(false);
- // Every time the path changes, announce the route change. The announcement will be prioritized by h1, then title
- // (from metadata), and finally if those don't exist, then the pathName that is in the URL. This methodology is
- // inspired by Marcy Sutton's accessible client routing user testing. More information can be found here:
+ // Every time the path changes, announce the new page’s title following this
+ // priority: first the document title (from head), otherwise the first h1, or
+ // if none of these exist, then the pathname from the URL. This methodology is
+ // inspired by Marcy Sutton’s accessible client routing user testing. More
+ // information can be found here:
// https://www.gatsbyjs.com/blog/2019-07-11-user-testing-accessible-client-routing/
_react.default.useEffect(
function() {
@@ -1857,20 +1860,22 @@
initialPathLoaded.current = true;
return;
}
- var newRouteAnnouncement;
- var pageHeader = document.querySelector("h1");
- if (pageHeader) {
- newRouteAnnouncement =
- pageHeader.innerText || pageHeader.textContent;
- }
- if (!newRouteAnnouncement) {
- if (document.title) {
- newRouteAnnouncement = document.title;
- } else {
- newRouteAnnouncement = asPath;
- }
+ if (document.title) {
+ setRouteAnnouncement(document.title);
+ } else {
+ var pageHeader = document.querySelector("h1");
+ var ref;
+ var content =
+ (ref =
+ pageHeader === null || pageHeader === void 0
+ ? void 0
+ : pageHeader.innerText) !== null && ref !== void 0
+ ? ref
+ : pageHeader === null || pageHeader === void 0
+ ? void 0
+ : pageHeader.textContent;
+ setRouteAnnouncement(content || asPath);
}
- setRouteAnnouncement(newRouteAnnouncement);
},
[asPath]
);
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-8b1326231534a220.js"
+ src="/_next/static/chunks/main-fea44d09f0f9fe3f.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-8b1326231534a220.js"
+ src="/_next/static/chunks/main-fea44d09f0f9fe3f.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-8b1326231534a220.js"
+ src="/_next/static/chunks/main-fea44d09f0f9fe3f.js"
defer=""
></script>
<script
Default Build with SWC (Increase detected ⚠️ )
General Overall increase ⚠️
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
buildDuration | 20.9s | 20.1s | -818ms |
buildDurationCached | 3.9s | 3.8s | -125ms |
nodeModulesSize | 332 MB | 332 MB |
Page Load Tests Overall decrease ⚠️
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 3.156 | 3.15 | -0.01 |
/ avg req/sec | 792.02 | 793.58 | +1.56 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.451 | 1.483 | |
/error-in-render avg req/sec | 1723.42 | 1685.68 |
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
450.HASH.js gzip | 179 B | 179 B | ✓ |
framework-HASH.js gzip | 42.3 kB | 42.3 kB | ✓ |
main-HASH.js gzip | 28.2 kB | 28.2 kB | |
webpack-HASH.js gzip | 1.43 kB | 1.43 kB | ✓ |
Overall change | 72.1 kB | 72.1 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.22 kB | 1.22 kB | ✓ |
_error-HASH.js gzip | 180 B | 180 B | ✓ |
amp-HASH.js gzip | 305 B | 305 B | ✓ |
css-HASH.js gzip | 321 B | 321 B | ✓ |
dynamic-HASH.js gzip | 2.38 kB | 2.38 kB | ✓ |
head-HASH.js gzip | 342 B | 342 B | ✓ |
hooks-HASH.js gzip | 622 B | 622 B | ✓ |
image-HASH.js gzip | 4.46 kB | 4.46 kB | ✓ |
index-HASH.js gzip | 256 B | 256 B | ✓ |
link-HASH.js gzip | 1.91 kB | 1.91 kB | ✓ |
routerDirect..HASH.js gzip | 314 B | 314 B | ✓ |
script-HASH.js gzip | 375 B | 375 B | ✓ |
withRouter-HASH.js gzip | 309 B | 309 B | ✓ |
334f979574ae..6f4.css gzip | 106 B | 106 B | ✓ |
Overall change | 13.1 kB | 13.1 kB | ✓ |
Client Build Manifests
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
_buildManifest.js gzip | 460 B | 460 B | ✓ |
Overall change | 460 B | 460 B | ✓ |
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary | KittyGiraudel/next.js document-title-announcer | Change | |
---|---|---|---|
index.html gzip | 521 B | 522 B | |
link.html gzip | 534 B | 535 B | |
withRouter.html gzip | 515 B | 515 B | ✓ |
Overall change | 1.57 kB | 1.57 kB |
Diffs
Diff for main-HASH.js
@@ -1842,14 +1842,17 @@
}
function RouteAnnouncer() {
var asPath = (0, _router).useRouter().asPath;
- var ref = _slicedToArray(_react.default.useState(""), 2),
- routeAnnouncement = ref[0],
- setRouteAnnouncement = ref[1];
- // Only announce the path change, but not for the first load because screen reader will do that automatically.
+ var ref1 = _slicedToArray(_react.default.useState(""), 2),
+ routeAnnouncement = ref1[0],
+ setRouteAnnouncement = ref1[1];
+ // Only announce the path change, but not for the first load because screen
+ // reader will do that automatically.
var initialPathLoaded = _react.default.useRef(false);
- // Every time the path changes, announce the route change. The announcement will be prioritized by h1, then title
- // (from metadata), and finally if those don't exist, then the pathName that is in the URL. This methodology is
- // inspired by Marcy Sutton's accessible client routing user testing. More information can be found here:
+ // Every time the path changes, announce the new page’s title following this
+ // priority: first the document title (from head), otherwise the first h1, or
+ // if none of these exist, then the pathname from the URL. This methodology is
+ // inspired by Marcy Sutton’s accessible client routing user testing. More
+ // information can be found here:
// https://www.gatsbyjs.com/blog/2019-07-11-user-testing-accessible-client-routing/
_react.default.useEffect(
function() {
@@ -1857,20 +1860,22 @@
initialPathLoaded.current = true;
return;
}
- var newRouteAnnouncement;
- var pageHeader = document.querySelector("h1");
- if (pageHeader) {
- newRouteAnnouncement =
- pageHeader.innerText || pageHeader.textContent;
- }
- if (!newRouteAnnouncement) {
- if (document.title) {
- newRouteAnnouncement = document.title;
- } else {
- newRouteAnnouncement = asPath;
- }
+ if (document.title) {
+ setRouteAnnouncement(document.title);
+ } else {
+ var pageHeader = document.querySelector("h1");
+ var ref;
+ var content =
+ (ref =
+ pageHeader === null || pageHeader === void 0
+ ? void 0
+ : pageHeader.innerText) !== null && ref !== void 0
+ ? ref
+ : pageHeader === null || pageHeader === void 0
+ ? void 0
+ : pageHeader.textContent;
+ setRouteAnnouncement(content || asPath);
}
- setRouteAnnouncement(newRouteAnnouncement);
},
[asPath]
);
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-8b1326231534a220.js"
+ src="/_next/static/chunks/main-fea44d09f0f9fe3f.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-8b1326231534a220.js"
+ src="/_next/static/chunks/main-fea44d09f0f9fe3f.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-8b1326231534a220.js"
+ src="/_next/static/chunks/main-fea44d09f0f9fe3f.js"
defer=""
></script>
<script
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improvement
This pull-request should address #24021, improving the page change announcement for assistive technologies by giving priority to
document.title
overh1
. Interestingly, it would also improve a potential performance bottleneck by skipping calls toinnerText
on the mainh1
raised in this comment.