Reconcile the authenticated Hop homepage link with the concurrent prompt UI cache-busting update.
Hop-State: A_06FN8H69P46VDF0HK6YF5QR Hop-Proposal: R_06FN8H5RRQKVJVY2JNSFBM0 Hop-Task: T_06FN8GMDFCS0GKTW2RRDQ70 Hop-Attempt: AT_06FN8H33JB50J4M5WD37BCR
This commit is contained in:
@@ -372,6 +372,42 @@
|
||||
}
|
||||
}
|
||||
|
||||
function publicHomepageRequested() {
|
||||
return new URLSearchParams(window.location.search).get('hop') === 'home';
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
document.documentElement.dataset.hopPublicHome = 'loading';
|
||||
try {
|
||||
const publicURL = new URL(link.href, window.location.origin);
|
||||
publicURL.search = '';
|
||||
const response = await fetch(publicURL, {credentials: 'omit'});
|
||||
if (!response.ok) throw new Error(`Could not load the Hop homepage (${response.status})`);
|
||||
|
||||
const publicDocument = new DOMParser().parseFromString(await response.text(), 'text/html');
|
||||
const publicMain = publicDocument.querySelector('#hop-main');
|
||||
const currentMain = document.querySelector('[role="main"]');
|
||||
if (!publicMain || !currentMain) throw new Error('The Hop homepage was not present in the response');
|
||||
|
||||
for (const style of publicMain.parentElement?.querySelectorAll(':scope > style') || []) {
|
||||
style.dataset.hopPublicHomeStyle = 'true';
|
||||
document.head.append(style);
|
||||
}
|
||||
currentMain.replaceWith(publicMain);
|
||||
document.title = publicDocument.title;
|
||||
document.documentElement.dataset.hopPublicHome = 'rendered';
|
||||
bindInstallationSwitchers();
|
||||
bindInstallationCopyButtons();
|
||||
} catch (error) {
|
||||
delete document.documentElement.dataset.hopPublicHome;
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
function applyHopSemantics() {
|
||||
const brandLogo = document.querySelector('#navbar-logo img');
|
||||
if (brandLogo) brandLogo.src = brandLogo.src.replace(/\/img\/(?:logo|hop)\.svg(?:\?.*)?$/, '/img/hop.svg?v=4');
|
||||
@@ -383,6 +419,7 @@
|
||||
renderPromptPage();
|
||||
bindInstallationSwitchers();
|
||||
bindInstallationCopyButtons();
|
||||
void loadPublicHomepage();
|
||||
document.documentElement.dataset.hopNative = 'true';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user