fix(script/jsx): cannot find preact hydration function

This commit is contained in:
Elian Doran
2025-12-20 19:45:44 +02:00
parent 88945788d6
commit 41220a9d1d
2 changed files with 13 additions and 5 deletions

View File

@@ -1,6 +1,5 @@
import { dayjs } from "@triliumnext/commons"; import { dayjs, formatLogMessage } from "@triliumnext/commons";
import { formatLogMessage } from "@triliumnext/commons"; import { Fragment, h, VNode } from "preact";
import { VNode } from "preact";
import appContext from "../components/app_context.js"; import appContext from "../components/app_context.js";
import type Component from "../components/component.js"; import type Component from "../components/component.js";
@@ -467,12 +466,17 @@ export interface Api {
*/ */
log(message: string | object): void; log(message: string | object): void;
// Preact support
/** /**
* Method that must be run for widget scripts that run on Preact, using JSX. The method just returns the same definition, reserved for future typechecking and perhaps validation purposes. * Method that must be run for widget scripts that run on Preact, using JSX. The method just returns the same definition, reserved for future typechecking and perhaps validation purposes.
* *
* @param definition the widget definition. * @param definition the widget definition.
*/ */
defineWidget(definition: WidgetDefinition): void; defineWidget(definition: WidgetDefinition): void;
h: typeof h;
Fragment: typeof Fragment;
} }
export interface WidgetDefinition { export interface WidgetDefinition {
@@ -739,12 +743,16 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
this.logMessages[noteId].push(message); this.logMessages[noteId].push(message);
this.logSpacedUpdates[noteId].scheduleUpdate(); this.logSpacedUpdates[noteId].scheduleUpdate();
}; };
// React support.
this.defineWidget = (definition) => { this.defineWidget = (definition) => {
return { return {
type: "react-widget", type: "react-widget",
...definition ...definition
}; };
}; };
this.h = h;
this.Fragment = Fragment;
} }
export default FrontendScriptApi as any as { export default FrontendScriptApi as any as {

View File

@@ -224,8 +224,8 @@ function buildJsx(jsxNote: BNote) {
const content = Buffer.isBuffer(contentRaw) ? contentRaw.toString("utf-8") : contentRaw; const content = Buffer.isBuffer(contentRaw) ? contentRaw.toString("utf-8") : contentRaw;
return transform(content, { return transform(content, {
transforms: ["jsx"], transforms: ["jsx"],
jsxPragma: "h", // for Preact jsxPragma: "api.h",
jsxFragmentPragma: "Fragment", jsxFragmentPragma: "api.Fragment",
}); });
} }