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,6 +3447,7 @@
return `${proto}//${window.location.host}/${communitySlug}/rspace`;
}
if (shareBadge) {
shareBadge.addEventListener("click", () => {
const isOpen = sharePanel.classList.toggle("open");
if (isOpen) {
@ -3458,12 +3459,13 @@
`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");
});
document.getElementById("share-copy-btn").addEventListener("click", async () => {
document.getElementById("share-copy-btn")?.addEventListener("click", async () => {
const url = document.getElementById("share-url").value;
await navigator.clipboard.writeText(url);
const btn = document.getElementById("share-copy-btn");
@ -3471,7 +3473,7 @@
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 status = document.getElementById("share-email-status");
if (!email) return;
@ -3500,9 +3502,9 @@
// Click-outside closes share panel
document.addEventListener("click", (e) => {
if (sharePanel.classList.contains("open") &&
if (sharePanel?.classList.contains("open") &&
!sharePanel.contains(e.target) &&
!shareBadge.contains(e.target)) {
(!shareBadge || !shareBadge.contains(e.target))) {
sharePanel.classList.remove("open");
}
});