[]previous and next page

warnOnce

Prints a development warning as [shadow CODE] detail, at most once per code for the life of the page or process (the same pattern as core's warn): for a custom renderer that refuses a value the way the built-in ones do.

Prints a development warning as [shadow CODE] detail, at most once per code for the life of the page or process (the same pattern as core's warn): for a custom renderer that refuses a value the way the built-in ones do. Production builds print nothing.

Import#

ts
import { warnOnce } from "@shadow-js/web/extend";

Signature#

ts
function warnOnce(code: WebWarningCode, detail: string): void

Parameters#

Name Description
code The diagnostic code. A code that was already reported is ignored, whatever the detail.
detail The text after the code.

Examples#

ts
import { isUnsafeUrlAttribute, warnOnce } from "@shadow-js/web/extend";

function setLink(el: Element, url: string): void {
  if (isUnsafeUrlAttribute("href", url)) {
    warnOnce("UNSAFE_URL_BLOCKED", `Blocked a script URL: ${url}`);
    return;
  }
  el.setAttribute("href", url);
}