feat(csr): add stripped dev output diagnostics
This commit is contained in:
@@ -18,8 +18,16 @@ export { REALTIME_RUNTIME } from "./realtime-runtime.ts";
|
||||
export { ACTION_RUNTIME } from "./action-runtime.ts";
|
||||
|
||||
/** The reactive runtime served at `/__wrnexus/reactive.js` (plain browser JS). */
|
||||
export function getReactiveRuntime(): string {
|
||||
return REACTIVE_RUNTIME;
|
||||
export function getReactiveRuntime(development = false): string {
|
||||
if (development) {
|
||||
return REACTIVE_RUNTIME
|
||||
.replace(/\/\*__WRNEXUS_DEV_START__\*\//g, "")
|
||||
.replace(/\/\*__WRNEXUS_DEV_END__\*\//g, "");
|
||||
}
|
||||
return REACTIVE_RUNTIME.replace(
|
||||
/\/\*__WRNEXUS_DEV_START__\*\/[\s\S]*?\/\*__WRNEXUS_DEV_END__\*\//g,
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
/** The client-side navigation runtime served at `/__wrnexus/nav.js`. */
|
||||
|
||||
@@ -191,6 +191,27 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
}
|
||||
}
|
||||
|
||||
/*__WRNEXUS_DEV_START__*/
|
||||
var developmentWarnings = Object.create(null);
|
||||
function warnOnce(code, message, element, detail) {
|
||||
var key = code + "\\n" + message;
|
||||
if (developmentWarnings[key]) return;
|
||||
developmentWarnings[key] = true;
|
||||
var payload = {
|
||||
code: code,
|
||||
message: message,
|
||||
hydrationId: element && element.getAttribute ? element.getAttribute("data-wrn-hydration") : null,
|
||||
detail: detail || null,
|
||||
};
|
||||
console.warn("[" + code + "] " + message, detail || "");
|
||||
try {
|
||||
window.dispatchEvent(new CustomEvent("wrnexus:diagnostic", { detail: payload }));
|
||||
} catch (_) {
|
||||
// CustomEvent can be unavailable in minimal DOM test environments.
|
||||
}
|
||||
}
|
||||
/*__WRNEXUS_DEV_END__*/
|
||||
|
||||
function scheduleUpdateHook(element, callback) {
|
||||
pendingUpdateHooks.set(element, callback);
|
||||
if (updateHooksScheduled) return;
|
||||
@@ -3953,6 +3974,15 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
? Promise.all(values)
|
||||
: values[values.length - 1];
|
||||
}
|
||||
/*__WRNEXUS_DEV_START__*/
|
||||
warnOnce(
|
||||
"WRN-DEV-OUTPUT-UNHANDLED",
|
||||
"Output '" + name + "' has no parent binding. Registered bindings: " +
|
||||
(registry ? Object.keys(registry).join(", ") || "none" : "none") + ".",
|
||||
root,
|
||||
{ output: name, registeredBindings: registry ? Object.keys(registry) : [] },
|
||||
);
|
||||
/*__WRNEXUS_DEV_END__*/
|
||||
return dispatchComponentEvent(root, name, payload);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user