Skip to content

Conversation

@spikeheap
Copy link
Contributor

@spikeheap spikeheap commented Jan 23, 2025

GitHub pages handles requests differently to the current setup for client-siderouting, which is causing 404 errors if you refresh a page or attempt to visit a URL provided by someone.

Screenshot 2025-01-23 at 09 55 (Brave Browser)

Why is this happenning?

The site is generated with links that don't have a trailing slash to denote a folder, e.g. href="/ways-of-working" when the actual HTML is stored in /ways-of-working/index.html. The client-side routing is configured in the same way, so within the site all links work. The build also succeeds because there are no invalid links according to the client-side routing rules.

That in itself is not a problem, however GitHub pages doesn't resolve a non-trailing slash path to the index.html within the folder. Instead it's looking for content in /ways-of-working.html, which doesn't exist. As a result no links that are generated or valid within the Docusaurus Single Page App will resolve when accessed directly in GitHub Pages.

The fix

This change configures Docusaurus to use trailing slashes for folders, which will change both the way it generates output folders/files and how client side routing works.

This should make client and server routing consistent and fix the problem. This hasn't been tested because we don't have a staging environment so the easiest way to validate the fix is to ship it to production and revert it if we don't get the results we want.

Side effects

The change in link handling highlighted a handful of broken links where the build system relied on an assumption about where the file would be. These have been updated to reference the content, which in turn allows Docusaurus to generate the appropriate link depending on how we've configured things. This is more robust and allows for an easier change in hosting provider should we ever consider that.

How to test

  1. Visit the playbook.hackey.gov.uk
  2. Navigate to Ways of Working
  3. Hard refresh or open the same link in a a new window.
  4. Validate that the page isn't a 404

@spikeheap spikeheap requested review from a team as code owners January 23, 2025 10:19
GitHub pages handles requests differently to the current setup for client-siderouting, which is causing 404 errors if you refresh a page or attempt to visit a URL provided by someone.

The site is generated with links that _don't_ have a trailing slash to denote a folder, e.g. `href="/ways-of-working"` when the actual HTML is stored in
`/ways-of-working/index.html`. The client-side routing is configured in the same way, so within the site all links work. The build also succeeds because there are no invalid links according to the client-side routing rules.

That in itself is not a problem, however GitHub pages doesn't resolve a non-trailing slash path to the  `index.html` within the folder. Instead it's looking for content in  `/ways-of-working.html`, which doesn't exist. As a result no links that are generated or valid within the Docusaurus Single Page App will resolve when accessed directly in GitHub Pages.

This change configures Docusaurus to use trailing slashes for folders, which will change both the way it generates output folders/files _and_ how client side routing works.

This _should_ make client and server routing consistent and fix the problem. This hasn't been tested because we don't have a staging environment so the easiest way to validate the fix is to ship it to production and revert it if we don't get the results we want.

1. Visit the playbook.hackey.gov.uk
2. Navigate to Ways of Working
3. Hard refresh or open the same link in a a new window.
4. Validate that the page isn't a 404
The previous commit changing trailingSlash handling to true introduced some broken links:

```
 Exhaustive list of all broken links found:
  - Broken link on source page path = /api-playbook/Governance/api_compliance/:
     -> linking to ../../api-playbook/ (resolved as: /api-playbook/api-playbook/)
  - Broken link on source page path = /api-playbook/Governance/developer_onboarding/:
     -> linking to ../../api-specifications/ (resolved as: /api-playbook/api-specifications/)
  - Broken link on source page path = /api-playbook/Support/creating_support_doc/:
     -> linking to ../../api-playbook/ (resolved as: /api-playbook/api-playbook/)
  - Broken link on source page path = /architecture-pillars/Development practices/api_compliance/:
     -> linking to ../../api-playbook/ (resolved as: /architecture-pillars/api-playbook/)
  - Broken link on source page path = /architecture-pillars/Development practices/developer_onboarding/:
     -> linking to ../../ways-of-working/ (resolved as: /architecture-pillars/ways-of-working/)
  - Broken link on source page path = /architecture-pillars/Reliability/core_resource_compliance/:
     -> linking to ../../api-playbook/ (resolved as: /architecture-pillars/api-playbook/)
```

Fixing these links to point directly to the source markdown file resolves the build failure and lets Docusaurus generate the correct final link (whether it has as trailing slash or not), so this approach is more robust.
Copy link
Contributor

@stonest stonest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it, works for me

@spikeheap spikeheap merged commit 26ee389 into main Jan 23, 2025
4 checks passed
@spikeheap spikeheap deleted the trailing-slash branch January 23, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants