chore: workaround missing jsr jsx transpilation (#3290)

This commit is contained in:
Marvin Hagemeister
2025-09-01 09:34:02 +02:00
committed by GitHub
parent 89a1fa317f
commit 54942987eb
7 changed files with 41 additions and 42 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ import {
FreshScripts, FreshScripts,
RenderState, RenderState,
setRenderState, setRenderState,
} from "./runtime/server/preact_hooks.tsx"; } from "./runtime/server/preact_hooks.ts";
import { DEV_ERROR_OVERLAY_URL, PARTIAL_SEARCH_PARAM } from "./constants.ts"; import { DEV_ERROR_OVERLAY_URL, PARTIAL_SEARCH_PARAM } from "./constants.ts";
import { tracer } from "./otel.ts"; import { tracer } from "./otel.ts";
import { import {
@@ -1,7 +1,7 @@
import { DEV_ERROR_OVERLAY_URL } from "../../../constants.ts"; import { DEV_ERROR_OVERLAY_URL } from "../../../constants.ts";
import { HttpError } from "../../../error.ts"; import { HttpError } from "../../../error.ts";
import type { Middleware } from "../../../middlewares/mod.ts"; import type { Middleware } from "../../../middlewares/mod.ts";
import { FreshScripts } from "../../../runtime/server/preact_hooks.tsx"; import { FreshScripts } from "../../../runtime/server/preact_hooks.ts";
import { ErrorOverlay } from "./overlay.tsx"; import { ErrorOverlay } from "./overlay.tsx";
export function devErrorOverlay<T>(): Middleware<T> { export function devErrorOverlay<T>(): Middleware<T> {
@@ -19,7 +19,7 @@ import {
PartialComp, PartialComp,
} from "./reviver.ts"; } from "./reviver.ts";
import { createRootFragment, isCommentNode, isElementNode } from "./reviver.ts"; import { createRootFragment, isCommentNode, isElementNode } from "./reviver.ts";
import type { PartialStateJson } from "../server/preact_hooks.tsx"; import type { PartialStateJson } from "../server/preact_hooks.ts";
import { parse } from "../../jsonify/parse.ts"; import { parse } from "../../jsonify/parse.ts";
import { INTERNAL_PREFIX, PARTIAL_SEARCH_PARAM } from "../../constants.ts"; import { INTERNAL_PREFIX, PARTIAL_SEARCH_PARAM } from "../../constants.ts";
@@ -1,4 +1,4 @@
import { type ComponentChildren, createContext } from "preact"; import { type ComponentChildren, createContext, h } from "preact";
export const HeadContext = createContext(false); export const HeadContext = createContext(false);
@@ -7,5 +7,5 @@ export interface HeadProps {
} }
export function Head(props: HeadProps): ComponentChildren { export function Head(props: HeadProps): ComponentChildren {
return <HeadContext value>{props.children}</HeadContext>; return h(HeadContext, { value: true }, props.children);
} }
@@ -31,9 +31,9 @@ import {
} from "../../constants.ts"; } from "../../constants.ts";
import { escape as escapeHtml } from "@std/html"; import { escape as escapeHtml } from "@std/html";
import { HttpError } from "../../error.ts"; import { HttpError } from "../../error.ts";
import { getCodeFrame } from "../../dev/middlewares/error_overlay/code_frame.tsx"; import { getCodeFrame } from "../../dev/middlewares/error_overlay/code_frame.ts";
import { escapeScript } from "../../utils.ts"; import { escapeScript } from "../../utils.ts";
import { HeadContext } from "../head.tsx"; import { HeadContext } from "../head.ts";
import { useContext } from "preact/hooks"; import { useContext } from "preact/hooks";
interface InternalPreactOptions extends PreactOptions { interface InternalPreactOptions extends PreactOptions {
@@ -529,20 +529,20 @@ export function FreshScripts() {
// Remaining slots must be rendered before creating the Fresh runtime // Remaining slots must be rendered before creating the Fresh runtime
// script, so that we have the full list of islands rendered // script, so that we have the full list of islands rendered
return ( return (
<> h(
{slots.map((slot) => { Fragment,
null,
slots.map((slot) => {
if (slot === null) return null; if (slot === null) return null;
return ( return (
<template h("template", {
key={slot.id} key: slot.id,
id={`frsh-${slot.id}-${slot.name}`} id: `frsh-${slot.id}-${slot.name}`,
> }, slot.vnode)
{slot.vnode}
</template>
); );
})} }),
<FreshRuntimeScript /> h(FreshRuntimeScript, null),
</> )
); );
} }
@@ -578,14 +578,13 @@ function FreshRuntimeScript() {
}; };
return ( return (
<script h("script", {
id={`__FRSH_STATE_${partialId}`} id: `__FRSH_STATE_${partialId}`,
type="application/json" type: "application/json",
// deno-lint-ignore react-no-danger dangerouslySetInnerHTML: {
dangerouslySetInnerHTML={{
__html: escapeScript(JSON.stringify(json), { json: true }), __html: escapeScript(JSON.stringify(json), { json: true }),
}} },
/> })
); );
} else { } else {
const islandImports = islandArr.map((island) => { const islandImports = islandArr.map((island) => {
@@ -617,17 +616,16 @@ function FreshRuntimeScript() {
`import { boot } from "${basePath}${runtimeUrl}";${islandImports}boot(${islandObj},${serializedProps});`; `import { boot } from "${basePath}${runtimeUrl}";${islandImports}boot(${islandObj},${serializedProps});`;
return ( return (
<> h(
<script Fragment,
type="module" null,
nonce={nonce} h("script", {
// deno-lint-ignore react-no-danger type: "module",
dangerouslySetInnerHTML={{ nonce,
__html: scriptContent, dangerouslySetInnerHTML: { __html: scriptContent },
}} }),
/> buildCache.features.errorOverlay ? h(ShowErrorOverlay, null) : null,
{buildCache.features.errorOverlay ? <ShowErrorOverlay /> : null} )
</>
); );
} }
} }
@@ -666,10 +664,11 @@ export function ShowErrorOverlay() {
} }
return ( return (
<iframe h("iframe", {
id="fresh-error-overlay" id: "fresh-error-overlay",
src={`${basePath}${DEV_ERROR_OVERLAY_URL}?${searchParams.toString()}`} src: `${basePath}${DEV_ERROR_OVERLAY_URL}?${searchParams.toString()}`,
style="unset: all; position: fixed; top: 0; left: 0; z-index: 99999; width: 100%; height: 100%; border: none;" style:
/> "unset: all; position: fixed; top: 0; left: 0; z-index: 99999; width: 100%; height: 100%; border: none;",
})
); );
} }
+1 -1
View File
@@ -53,4 +53,4 @@ export function Partial(props: PartialProps): VNode {
} }
Partial.displayName = "Partial"; Partial.displayName = "Partial";
export { Head, type HeadProps } from "./head.tsx"; export { Head, type HeadProps } from "./head.ts";