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:
parent
de828c4247
commit
646c3fcaf3
|
|
@ -3447,23 +3447,25 @@
|
|||
return `${proto}//${window.location.host}/${communitySlug}/rspace`;
|
||||
}
|
||||
|
||||
shareBadge.addEventListener("click", () => {
|
||||
const isOpen = sharePanel.classList.toggle("open");
|
||||
if (isOpen) {
|
||||
// Close people panel if open
|
||||
peoplePanel.classList.remove("open");
|
||||
const url = getShareUrl();
|
||||
document.getElementById("share-url").value = url;
|
||||
document.getElementById("share-qr").src =
|
||||
`https://api.qrserver.com/v1/create-qr-code/?size=180x180&data=${encodeURIComponent(url)}`;
|
||||
}
|
||||
});
|
||||
if (shareBadge) {
|
||||
shareBadge.addEventListener("click", () => {
|
||||
const isOpen = sharePanel.classList.toggle("open");
|
||||
if (isOpen) {
|
||||
// Close people panel if open
|
||||
peoplePanel.classList.remove("open");
|
||||
const url = getShareUrl();
|
||||
document.getElementById("share-url").value = 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");
|
||||
});
|
||||
|
||||
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");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue