Files
prompts.chat/src/lib/ezoic.ts
T
yoloni 256e4339f5 fix: remove redundant non-null assertions in ezoic.ts
The ??= operator already guarantees that `ez` is non-null by the time
it is assigned, so the subsequent non-null assertions (!.) on `ez.cmd`
are redundant and can be safely removed.

Before:
  ez!.cmd = ez!.cmd || [];
  ez!.cmd.push(fn);

After:
  ez.cmd = ez.cmd || [];
  ez.cmd.push(fn);
2026-03-21 17:07:40 +08:00

14 lines
494 B
TypeScript

/**
* Safely push a function to the Ezoic command queue.
* Initializes window.ezstandalone and cmd array if they don't exist yet,
* preventing errors when components mount before the Ezoic script loads.
*
* @see https://docs.ezoic.com/docs/ezoicadsadvanced/nextjs/
*/
export function runEzoic(fn: () => void) {
if (typeof window === "undefined") return;
const ez = (window.ezstandalone ??= {} as NonNullable<typeof window.ezstandalone>);
ez.cmd = ez.cmd || [];
ez.cmd.push(fn);
}