From 3777ba22ca95da2bb992f975ec2f0ccca6315afa Mon Sep 17 00:00:00 2001 From: shenlan Date: Sun, 9 Nov 2025 16:34:54 +0800 Subject: [PATCH] Ensure html2canvas loads only in browser (#652) --- dashboard/app/[slug]/Client.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dashboard/app/[slug]/Client.tsx b/dashboard/app/[slug]/Client.tsx index 273e5d1..93e4bf7 100644 --- a/dashboard/app/[slug]/Client.tsx +++ b/dashboard/app/[slug]/Client.tsx @@ -7,6 +7,10 @@ type Html2CanvasFn = typeof import('html2canvas')['default'] let html2canvasLoader: Promise | null = null const loadHtml2Canvas = async (): Promise => { + if (typeof window === 'undefined') { + throw new Error('html2canvas can only be loaded in the browser') + } + if (!html2canvasLoader) { html2canvasLoader = import('html2canvas').then((module) => module.default) } @@ -62,7 +66,7 @@ const drawQR = async ( } const exportPoster = async (node: HTMLElement | null, slug: string) => { - if (!node) { + if (!node || typeof window === 'undefined') { return }