Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/_overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@
// above it. Resolving the bare relative `base_url` against `location`
// yields an absolute URL; popping only the page's last path segment (the
// previous approach) 404s on deep pages.
var versionRoot = new URL("{{ base_url }}/", window.location);
var versionsUrl = new URL("../versions.json", versionRoot).toString();
//
// AAASM-4317: guard the URL constructors so that a malformed or empty
// template value (e.g. a stray build variant where `base_url` renders
// blank) cannot throw `TypeError: Failed to construct 'URL': Invalid URL`
// and leave a visible page-load error in the console. On failure we keep
// the static fallback copy that is already rendered above.
var versionRoot;
var versionsUrl;
try {
versionRoot = new URL("{{ base_url }}/", window.location);
versionsUrl = new URL("../versions.json", versionRoot).toString();
} catch (e) {
return;
}

// The current version id is the last path segment of the deploy root.
var current =
Expand Down
11 changes: 7 additions & 4 deletions docs/_overrides/partials/javascripts/outdated.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
`..`, which is not an absolute URL, so `new URL("..")` throws
`TypeError: Failed to construct 'URL': Invalid URL` on every page load.

The only change here is passing `location` as the base so the relative
`base_url` resolves against the current page. Behaviour is otherwise identical
to Material's generated script.
Passing `location` as the base resolves the relative `base_url` against the
current page. The try/catch (AAASM-4317) is defense-in-depth: any future
template regression that renders `base_url` as an unparseable value (e.g. an
empty string on a build variant that omits `site_url`) will silently no-op
the outdated banner instead of surfacing a page-load TypeError. Behaviour is
otherwise identical to Material's generated script.
-#}
<script>var el=document.querySelector("[data-md-component=outdated]"),base=new URL("{{ base_url }}",location),outdated=__md_get("__outdated",sessionStorage,base);!0===outdated&&el&&(el.hidden=!1)</script>
<script>try{var el=document.querySelector("[data-md-component=outdated]"),base=new URL("{{ base_url }}",location),outdated=__md_get("__outdated",sessionStorage,base);!0===outdated&&el&&(el.hidden=!1)}catch(e){}</script>
Binary file added docs/verify/AAASM-4317-clean-console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/verify/pr2-guides-nested.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.