Skip to content
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(ci/preview): add custom 404 page for PR preview pages #37769

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

OnkarRuikar
Copy link
Contributor

@OnkarRuikar OnkarRuikar commented Jan 23, 2025

The current 404 page shows following content:


Message: The specified key does not exist.
Key: pr37670/en-us/_spas/404.html
RequestId: W9ZG8PFR8V5N0MK5
HostId: EoaAHM8g7wgSv7rGa1dRb6/F9o5Pg93I6h0iZVYuA8A5x1RrlpNKgHZVADEZDyl/ZnC2KuEdIr8=

From the error, when 404 occurs, the Cloudfront is trying to look for /en-us/_spas/404.html. We can put a custom 404.html file there to provide the link to prod pages.

Tested the changes successfully:

404_page.mp4

I had to put JS in a separate file to avoid inline script CSP error. To have the JS in the same HTML we'll have to add CSP hash to mdn/yari//libs/constants/index.js. The preview build is not part of the MDN platform so let's not involve yari repo.

@OnkarRuikar OnkarRuikar requested a review from a team as a code owner January 23, 2025 10:02
@github-actions github-actions bot added system [PR only] Infrastructure and configuration for the project size/s [PR only] 6-50 LoC changed labels Jan 23, 2025
@OnkarRuikar OnkarRuikar changed the title fix(ci/preview): add custom 404 page fix(ci/preview): add custom 404 page for PR preview pages Jan 23, 2025
@OnkarRuikar OnkarRuikar requested a review from a team as a code owner January 23, 2025 10:25
@OnkarRuikar OnkarRuikar requested review from chrisdavidmills and removed request for a team January 23, 2025 10:25
@github-actions github-actions bot added the Content:CSS Cascading Style Sheets docs label Jan 23, 2025
Copy link
Contributor

github-actions bot commented Jan 23, 2025

Preview URLs

(comment last updated: 2025-01-24 05:05:09)

@github-actions github-actions bot removed the Content:CSS Cascading Style Sheets docs label Jan 23, 2025
@github-actions github-actions bot added the merge conflicts 🚧 [PR only] label Jan 23, 2025
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions github-actions bot removed the merge conflicts 🚧 [PR only] label Jan 23, 2025
@caugner
Copy link
Contributor

caugner commented Jan 23, 2025

Note that due to the fix mentioned here, for your custom 404 page to work, you'll need to overwrite /404/index.html after the rsync command in the next step.

I'll let content folks (cc @Rumyra) decide whether your proposed custom 404 page with a link to production is more useful than the generic 404 page.

@yin1999
Copy link
Member

yin1999 commented Jan 23, 2025

Related issue in yari: mdn/yari#7185

.github/workflows/404.js Outdated Show resolved Hide resolved
@OnkarRuikar
Copy link
Contributor Author

OnkarRuikar commented Jan 24, 2025

I'll let content folks (cc @Rumyra) decide whether your proposed custom 404 page with a link to production is more useful than the generic 404 page.

If we have View on MDN prod link on the generic 404 page when in dev environments, then we won't need this workaround. From the code comment I thought we don't want this CI specific stuff in platform code that is why I made the fix here.

@github-actions github-actions bot added the Content:CSS Cascading Style Sheets docs label Jan 24, 2025
@github-actions github-actions bot removed the Content:CSS Cascading Style Sheets docs label Jan 24, 2025
@estelle
Copy link
Member

estelle commented Jan 27, 2025

Thanks for adding this feature Onkar. This looks like it will be useful.

One suggestion, though people may disagree:
in addition to link.textContent = "View on MDN production server";
maybe we can add a "You are currently in a PR, so this page is not available" or something similar before it, just as clarification.

.github/workflows/404.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/s [PR only] 6-50 LoC changed system [PR only] Infrastructure and configuration for the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PR preview pages don't handle visit to non deployed pages well
5 participants