fix(canvas): null-guard share-badge to prevent crash on shell-wrapped pages

The canvas header is stripped when served via renderShell (extractCanvasContent),
removing the #share-badge button. The JS then crashes on shareBadge.addEventListener
which prevents all canvas interaction. Add null guards for all share panel elements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-03-16 15:58:26 -07:00
parent de828c4247
commit 646c3fcaf3
1 changed files with 18 additions and 16 deletions

View File

@ -3447,23 +3447,25 @@
return `${proto}//${window.location.host}/${communitySlug}/rspace`; return `${proto}//${window.location.host}/${communitySlug}/rspace`;
} }
shareBadge.addEventListener("click", () => { if (shareBadge) {
const isOpen = sharePanel.classList.toggle("open"); shareBadge.addEventListener("click", () => {
if (isOpen) { const isOpen = sharePanel.classList.toggle("open");
// Close people panel if open if (isOpen) {
peoplePanel.classList.remove("open"); // Close people panel if open
const url = getShareUrl(); peoplePanel.classList.remove("open");
document.getElementById("share-url").value = url; const url = getShareUrl();
document.getElementById("share-qr").src = document.getElementById("share-url").value = url;
`https://api.qrserver.com/v1/create-qr-code/?size=180x180&data=${encodeURIComponent(url)}`; document.getElementById("share-qr").src =
} `https://api.qrserver.com/v1/create-qr-code/?size=180x180&data=${encodeURIComponent(url)}`;
}); }
});
}
document.getElementById("share-panel-close").addEventListener("click", () => { document.getElementById("share-panel-close")?.addEventListener("click", () => {
sharePanel.classList.remove("open"); sharePanel.classList.remove("open");
}); });
document.getElementById("share-copy-btn").addEventListener("click", async () => { document.getElementById("share-copy-btn")?.addEventListener("click", async () => {
const url = document.getElementById("share-url").value; const url = document.getElementById("share-url").value;
await navigator.clipboard.writeText(url); await navigator.clipboard.writeText(url);
const btn = document.getElementById("share-copy-btn"); const btn = document.getElementById("share-copy-btn");
@ -3471,7 +3473,7 @@
setTimeout(() => btn.textContent = "Copy", 2000); setTimeout(() => btn.textContent = "Copy", 2000);
}); });
document.getElementById("share-send-btn").addEventListener("click", async () => { document.getElementById("share-send-btn")?.addEventListener("click", async () => {
const email = document.getElementById("share-email").value.trim(); const email = document.getElementById("share-email").value.trim();
const status = document.getElementById("share-email-status"); const status = document.getElementById("share-email-status");
if (!email) return; if (!email) return;
@ -3500,9 +3502,9 @@
// Click-outside closes share panel // Click-outside closes share panel
document.addEventListener("click", (e) => { document.addEventListener("click", (e) => {
if (sharePanel.classList.contains("open") && if (sharePanel?.classList.contains("open") &&
!sharePanel.contains(e.target) && !sharePanel.contains(e.target) &&
!shareBadge.contains(e.target)) { (!shareBadge || !shareBadge.contains(e.target))) {
sharePanel.classList.remove("open"); sharePanel.classList.remove("open");
} }
}); });