-
Notifications
You must be signed in to change notification settings - Fork 30
implement football more button for when js is disabled #13903
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
Conversation
Size Change: +210 B (+0.02%) Total Size: 973 kB
ℹ️ View Unchanged
|
<div css={footballMatchesGridStyles}> | ||
<div | ||
<a |
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 think this is minor, raising out of interest. Nesting a button inside a link is not valid HTML:
Content model:
Transparent, but there must be no interactive content descendant, a element descendant, or descendant with the tabindex attribute specified.
There might be weird behaviour as a result.
An alternative solution might be to retain the outer <div>
and only hide the <a>
if JS loads. I haven't tested this.
<div>
{
jsLoaded ?
(<Button></Button>)
:
(<LinkButton></LinkButton>)
}
</div>
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 @SiAdcock for pointing this out and sharing the links. I made some changes and used a state jsEnabled
which is set within a useEffect
. Using that the component decides if it needs to use the link or the button. What do you think about this approach?
Hello 👋! When you're ready to run Chromatic, please apply the You will need to reapply the label each time you want to run Chromatic. |
9a13902
to
0d4dc52
Compare
useEffect(() => { | ||
// This will only run after JS has loaded on the client | ||
setJsLoaded(true); | ||
}, []); |
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.
So sorry @marjisound, I've just noticed we have a useHydrated
hook that does the same thing. Would you be able to use it here?
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.
Ah thanks for letting me know, just changed it to use the useHydrated
hook
0d4dc52
to
6e1f9e8
Compare
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! Couple of questions.
export const nextPageNoJsUrl = | ||
'https://www.theguardian.com/football/fixtures/more/2025/May/05'; |
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.
Aren't the routes with /more
in the path being deprecated?
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.
Good point, I removed the more from the url
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.
👍 for these storybook tests!
onClick={(e) => { | ||
e.preventDefault(); // prevent navigation when JS is enabled |
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.
If there's no link wrapping the button now is this still needed?
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.
You're right. I removed it 👍
- remove the preventDefault from button click handler - update the nextPageNoJsUrl value in fixtures Also fixing the bug where the parser was incorrectly using ajaxUrl as the for nextPageNoJsUrl.
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.
Wonderful, thanks @marjisound 🙏
Seen on PROD (merged by @marjisound 9 minutes and 56 seconds ago) Please check your changes! |
What does this change?
This change adds support for a fallback
More
button on the football matches pages for when JavaScript is disabled in the browser.Why introduce nextPageNoJsUrl:
There is a convention in frontend routing where for any page route (e.g. /football/fixtures/more/:year/:month/:day), there is also a corresponding .json route (e.g. /football/fixtures/more/:year/:month/:day.json). These .json routes return the full data required to render a page, including config and navigation.
In DCAR the
More
button is using the .json route to fetch more matches. However, this returns far more data than necessary — config, nav, and other unrelated information — when all that is needed is a list of matches to append to the current view.Upon further investigation, we noticed that the HTML version of the
/more/
routes serves the same content as the equivalent non-/more/ routes. Based on this, we decided to remove the HTML versions of the /more/ routes to simplify routing. The PR for this: guardian/frontend#27939However, we later realised that the DCAR implementation did not support a non-JavaScript experience for the More button. To fix this, we needed a way to render the More button as a fallback link (i.e. an anchor tag) that simply navigates to the next page of matches when JavaScript is disabled.
Since the
/more/
routes are being deprecated, we now use the equivalent non-/more/ route to construct that fallback link — this is provided via the newnextPageNoJsUrl
prop.TOTO:
This PR can be merged after guardian/frontend#27946