Add CF custom error pages - #766
Conversation
davidfischer
commented
Jul 8, 2026
- Excluded these from pre-commit as they intentionally have inline styles
- Punted for now on adapting a subset of our styles for inlining
- Partially resolves Errors: use application errors from CF and ALBs #469 (the CF part but not the ALB part)
- Excluded these from pre-commit as they intentionally have inline styles - Punted for now on adapting a subset of our styles for inlining
Do we need to use a subset? We hit this pretty quickly the last time we tried this but maybe the limit was lower.
I'm guessing what is/was happening is that our CSS is only 800kB on disk but then that tries to also inline the fonts/etc, exceeding 1.5MB. These error messages should match our existing look and feel, especially on customer documentation projects. They're pretty one-off feeling right now. It's better than Cloudflare branding these error pages at least though. There are some modifications that would make this fit better temporarily, but I also won't want to get too far away from finishing this work either way. We'll want to follow up with pages that use our existing styles and structure so these don't feel so out of place. |
agjohnson
left a comment
There was a problem hiding this comment.
Assuming reusing our styles is a harder task, this looks okay temporarily. I commented on the first file, but most of that applies to all the files. A second pass at these can explore trimming our existing CSS down and perhaps consider a dark theme, though I wouldn't support that unless we decide to support our dark theme without user authentication.
| --text-color: #18181b; | ||
| --box-bg: #ffffff; | ||
| --border-color: #e4e4e7; | ||
| --accent-color: #dc2626; /* Red for blocking */ |
There was a problem hiding this comment.
We should match the already used site colors here, especially for the accents though.
There was a problem hiding this comment.
We already have the template path readthedocsext/theme/errors/, let's use errors in the path instead of error-pages to reduce confusion between the two.
| /* Automatic Dark Mode Support */ | ||
| @media (prefers-color-scheme: dark) { | ||
| :root { | ||
| --bg-color: #09090b; | ||
| --text-color: #f4f4f5; | ||
| --box-bg: #18181b; | ||
| --border-color: #27272a; | ||
| --accent-color: #ef4444; | ||
| --light-svg-display: none; | ||
| --dark-svg-display: block; | ||
| } | ||
| } |
There was a problem hiding this comment.
We don't support dark themes on the current error pages and this is probably most of what feels so out of place currently. I might say drop dark mode from this pass.
| svg.dark { | ||
| display: var(--dark-svg-display); | ||
| } |
There was a problem hiding this comment.
No need for multiple SVGs, we can use CSS to invert:
| svg.dark { | |
| display: var(--dark-svg-display); | |
| } | |
| svg.dark { | |
| filter: invert(100) brightness(110); | |
| } |
That assumes the dark color text SVG for use on white background, inverted to be (brighter) white.
| <svg class="dark" | ||
| version="1.1" | ||
| id="svg" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| xmlns:xlink="http://www.w3.org/1999/xlink" | ||
| x="0px" | ||
| y="0px" | ||
| viewBox="694 197 2000 400"> |
There was a problem hiding this comment.
I don't think we need to hardcode this. If you reference the hosted SVG, Cloudflare will inline it for us. Then we don't need to keep multiple hardcoded copies around.
https://app-assets.readthedocs.org/readthedocsext/theme/images/logo-wordmark-dark.svg
There was a problem hiding this comment.
There's a lot of advantages to having the page served by others (Cloudflare) being a single self-contained page. We can rely on Cloudflare to handle serving other content correctly, but it'd be a lot simpler and a lot harder to get wrong if the error page was entirely self-contained.
There was a problem hiding this comment.
It would still be self-contained, Cloudflare automatically does all of the inlining instead of referencing a URL1:
When you provide a URL for a custom error asset, Cloudflare fetches the page and inlines all referenced resources into the HTML. Images and other binary resources (including those referenced from CSS via url(...)) are inlined as base64-encoded data URLs.
Footnotes
There was a problem hiding this comment.
No I get that. I just think there are additional advantages to having it actually be self-contained by design rather than relying on Cloudflare to magically make it self-contained.
There was a problem hiding this comment.
Yeah I get that it's more explicit, but if we aren't hitting any issues with Cloudflare inlining of these files then it seems fine to lean on Cloudflare and keep our maintenance simple. The long term goal would be to feed Cloudflare these pages through our templates, so would end up relying directly on static file collection.
…anaged_challenge.html Co-authored-by: Anthony <aj@ohess.org>
We don't strictly need to but there's a lot of nice aspects of having the entire error page being self-contained. We can rely on Cloudflare to "just handle it" but it'd be a lot harder to get wrong and a lot more portable if we had self-contained error pages. I can attempt to match the styles/colors a little closer and possibly inline a small subset, but unless you are dead-set on it, I'd advise against using our full styles. If we do go that route, I'd probably just make this a template that uses other styles rather than a static file collected with |
|
Well, I'd say just the changes above are enough for a first pass -- skipping dark mode and using colors from our styles. Long term, these error pages should definitely match our dashboard errors but for a first pass the basic style is okay. They just should stick to a look and feel that isn't too far removed from our current, it's a bit confusing when we give varying UX/styles. When we polish these up to match our current styles, I wouldn't use the full stylesheet here due to the size but I would use just the rules we need to make it look like the other error pages. And yeah, the idea was to make this a template long term too. But similarly, we can keep this simple by just leaving them as static files to start. Eventually we'd author them alongside all of our other error templates and feed them to Cloudflare through our existing ErrorView. In this world, our templates handle the static files so we wouldn't have hardcoded inlines for images/etc. |
- Remove dark mode - Add colors from dashboard stylesheets - Add border-bottom to H1
|
Ok, I updated the styles on these pages to match the dashboard styles. They're still static, self-contained HTML rather than templates, but this should give us a first pass. |