Gate authenticated homepage rendering until the public Hop home swap completes, with failure fallback and regression tests
Hop-State: A_06FNBF34SYZE98C5FTCSNQ8 Hop-Proposal: R_06FNBF2AQPTF8B2YVMQ8NJG Hop-Task: T_06FNBEGE901NTR8R2RAPC70 Hop-Attempt: AT_06FNBEGE90FVP4AP4KQ3E40
This commit is contained in:
@@ -345,15 +345,37 @@
|
||||
return new URLSearchParams(window.location.search).get('hop') === 'home';
|
||||
}
|
||||
|
||||
function signedIn() {
|
||||
return Boolean(document.querySelector('meta[name="hop-signed-user-id"]'));
|
||||
}
|
||||
|
||||
function revealHopPage() {
|
||||
document.documentElement.dataset.hopNative = 'true';
|
||||
}
|
||||
|
||||
async function loadPublicHomepage() {
|
||||
const link = document.querySelector('[data-hop-public-home-link]');
|
||||
if (link) link.classList.toggle('active', publicHomepageRequested());
|
||||
if (!link || !publicHomepageRequested() || document.documentElement.dataset.hopPublicHome) return;
|
||||
if (!publicHomepageRequested()) return;
|
||||
|
||||
if (document.querySelector('#hop-main')) {
|
||||
document.documentElement.dataset.hopPublicHome = 'rendered';
|
||||
revealHopPage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!signedIn()) {
|
||||
revealHopPage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.documentElement.dataset.hopPublicHome) return;
|
||||
|
||||
document.documentElement.dataset.hopPublicHome = 'loading';
|
||||
try {
|
||||
const publicURL = new URL(link.href, window.location.origin);
|
||||
const publicURL = new URL(link?.href || window.location.href, window.location.origin);
|
||||
publicURL.search = '';
|
||||
publicURL.hash = '';
|
||||
const response = await fetch(publicURL, {credentials: 'omit'});
|
||||
if (!response.ok) throw new Error(`Could not load the Hop homepage (${response.status})`);
|
||||
|
||||
@@ -372,8 +394,10 @@
|
||||
bindInstallationSwitchers();
|
||||
bindInstallationCopyButtons();
|
||||
} catch (error) {
|
||||
delete document.documentElement.dataset.hopPublicHome;
|
||||
document.documentElement.dataset.hopPublicHome = 'failed';
|
||||
console.error(error);
|
||||
} finally {
|
||||
revealHopPage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +413,12 @@
|
||||
bindInstallationSwitchers();
|
||||
bindInstallationCopyButtons();
|
||||
void loadPublicHomepage();
|
||||
document.documentElement.dataset.hopNative = 'true';
|
||||
const publicHomepageNeedsSwap = publicHomepageRequested()
|
||||
&& signedIn()
|
||||
&& !document.querySelector('#hop-main');
|
||||
if (!publicHomepageNeedsSwap || document.documentElement.dataset.hopPublicHome === 'failed') {
|
||||
revealHopPage();
|
||||
}
|
||||
}
|
||||
|
||||
let queued = false;
|
||||
|
||||
Reference in New Issue
Block a user