fix: meta charSet -> charset (#1875)
This commit is contained in:
Vendored
+5
-5
@@ -6,11 +6,11 @@
|
|||||||
"$fresh/": "../",
|
"$fresh/": "../",
|
||||||
"twind": "https://esm.sh/twind@0.16.19",
|
"twind": "https://esm.sh/twind@0.16.19",
|
||||||
"twind/": "https://esm.sh/twind@0.16.19/",
|
"twind/": "https://esm.sh/twind@0.16.19/",
|
||||||
"preact": "https://esm.sh/preact@10.15.1",
|
"preact": "https://esm.sh/preact@10.18.1",
|
||||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
"preact/": "https://esm.sh/preact@10.18.1/",
|
||||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
|
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2",
|
||||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.1",
|
||||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
|
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.5.0",
|
||||||
"@preact/signals-core@1.2.3": "https://esm.sh/@preact/signals-core@1.2.3",
|
"@preact/signals-core@1.2.3": "https://esm.sh/@preact/signals-core@1.2.3",
|
||||||
"@preact/signals-core@1.3.0": "https://esm.sh/@preact/signals-core@1.3.0",
|
"@preact/signals-core@1.3.0": "https://esm.sh/@preact/signals-core@1.3.0",
|
||||||
"$std/": "https://deno.land/std@0.193.0/",
|
"$std/": "https://deno.land/std@0.193.0/",
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
---
|
||||||
|
description: |
|
||||||
|
Add a global app wrapper to provide common meta tags or context for application routes.
|
||||||
|
---
|
||||||
|
|
||||||
|
An app wrapper is defined in an `_app.tsx` file in `routes/` folder and is
|
||||||
|
typically used to create the outer structure of an HTML document. It must
|
||||||
|
contain a default export that is a regular Preact component. Only one such
|
||||||
|
wrapper is allowed per application.
|
||||||
|
|
||||||
|
The component to be wrapped is received via props, in addition to a few other
|
||||||
|
things. This allows for the introduction of a global container functioning as a
|
||||||
|
template which can be conditioned based on state and params. Note that any state
|
||||||
|
set by middleware is available via `props.state`.
|
||||||
|
|
||||||
|
```tsx routes/_app.tsx
|
||||||
|
import { AppProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export default function App({ Component, state }: AppProps) {
|
||||||
|
// do something with state here
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>My Fresh app</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<Component />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Async app wrapper
|
||||||
|
|
||||||
|
Similar to routes and layouts, the app wrapper can be made asynchronous. This
|
||||||
|
changes the function signature so that the first argument is the `Request`
|
||||||
|
instance and the second one is the `AppContext`.
|
||||||
|
|
||||||
|
```tsx routes/_app.tsx
|
||||||
|
import { AppContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export default async function App(req: Request, ctx: AppContext) {
|
||||||
|
const data = await loadData();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>My Fresh app</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello {data.name}</h1>
|
||||||
|
<ctx.Component />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Define helper
|
||||||
|
|
||||||
|
To make it quicker to type the async app wrapper, Fresh includes a `defineApp`
|
||||||
|
helper which already infers the correct types for you.
|
||||||
|
|
||||||
|
```tsx routes/_app.tsx
|
||||||
|
import { defineApp } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export default defineApp(async (req, ctx) => {
|
||||||
|
const data = await loadData();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>My Fresh app</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello {data.name}</h1>
|
||||||
|
<ctx.Component />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Disabling the app wrapper
|
||||||
|
|
||||||
|
Rendering the app wrapper can be skipped on a route or layout basis. To do that,
|
||||||
|
set `skipAppWrapper: true` to the layout or route config.
|
||||||
|
|
||||||
|
```tsx routes/my-special-route.tsx
|
||||||
|
import { RouteConfig } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export const config: RouteConfig = {
|
||||||
|
skipAppWrapper: true, // Skip the app wrapper during rendering
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -21,7 +21,7 @@ export default function App({ Component, state }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>My Fresh app</title>
|
<title>My Fresh app</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -48,7 +48,7 @@ export default async function App(req: Request, ctx: AppContext) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>My Fresh app</title>
|
<title>My Fresh app</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -75,7 +75,7 @@ export default defineApp(async (req, ctx) => {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>My Fresh app</title>
|
<title>My Fresh app</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ const toc: RawTableOfContents = {
|
|||||||
["server-components", "Server Components", "link:latest"],
|
["server-components", "Server Components", "link:latest"],
|
||||||
["routing", "Routing", "link:latest"],
|
["routing", "Routing", "link:latest"],
|
||||||
["routes", "Routes", "link:latest"],
|
["routes", "Routes", "link:latest"],
|
||||||
["app-wrapper", "App wrapper", "link:latest"],
|
["app-wrapper", "App wrapper", "link:canary"],
|
||||||
["layouts", "Layouts", "link:latest"],
|
["layouts", "Layouts", "link:latest"],
|
||||||
["forms", "Forms", "link:latest"],
|
["forms", "Forms", "link:latest"],
|
||||||
["islands", "Interactive islands", "link:latest"],
|
["islands", "Interactive islands", "link:latest"],
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ export default function App({ Component }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>${basename(resolvedDirectory)}</title>
|
<title>${basename(resolvedDirectory)}</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -455,7 +455,7 @@ export default function App({ Component }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>${basename(resolvedDirectory)}</title>
|
<title>${basename(resolvedDirectory)}</title>
|
||||||
<link rel="stylesheet" href="/styles.css" />
|
<link rel="stylesheet" href="/styles.css" />
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
export const RECOMMENDED_PREACT_VERSION = "10.15.1";
|
export const RECOMMENDED_PREACT_VERSION = "10.18.1";
|
||||||
export const RECOMMENDED_PREACT_RTS_VERSION = "6.2.1";
|
export const RECOMMENDED_PREACT_RTS_VERSION = "6.2.2";
|
||||||
export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.1.3";
|
export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.2.1";
|
||||||
export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.2.3";
|
export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.5.0";
|
||||||
export const RECOMMENDED_TWIND_VERSION = "0.16.19";
|
export const RECOMMENDED_TWIND_VERSION = "0.16.19";
|
||||||
export const RECOMMENDED_STD_VERSION = "0.193.0";
|
export const RECOMMENDED_STD_VERSION = "0.193.0";
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export function revive(
|
|||||||
[],
|
[],
|
||||||
// Keep a root node in the vnode stack to save a couple of checks
|
// Keep a root node in the vnode stack to save a couple of checks
|
||||||
// later during iteration
|
// later during iteration
|
||||||
[h(Fragment, null)],
|
[h(Fragment, null) as VNode],
|
||||||
document.body,
|
document.body,
|
||||||
result,
|
result,
|
||||||
);
|
);
|
||||||
@@ -324,11 +324,11 @@ function _walkInner(
|
|||||||
});
|
});
|
||||||
|
|
||||||
vnodeStack.push(
|
vnodeStack.push(
|
||||||
h(PartialComp, { name, key, mode: +mode }),
|
h(PartialComp, { name, key, mode: +mode }) as VNode,
|
||||||
);
|
);
|
||||||
} else if (comment.startsWith("frsh-key")) {
|
} else if (comment.startsWith("frsh-key")) {
|
||||||
const key = comment.slice("frsh-key:".length);
|
const key = comment.slice("frsh-key:".length);
|
||||||
vnodeStack.push(h(Fragment, { key }));
|
vnodeStack.push(h(Fragment, { key }) as VNode);
|
||||||
} else if (comment.startsWith("/frsh-key")) {
|
} else if (comment.startsWith("/frsh-key")) {
|
||||||
const vnode = vnodeStack.pop();
|
const vnode = vnodeStack.pop();
|
||||||
const parent = vnodeStack[vnodeStack.length - 1]!;
|
const parent = vnodeStack[vnodeStack.length - 1]!;
|
||||||
@@ -453,7 +453,7 @@ function _walkInner(
|
|||||||
kind: MarkerKind.Island,
|
kind: MarkerKind.Island,
|
||||||
});
|
});
|
||||||
|
|
||||||
const vnode = h(islands[id][exportName], islandProps);
|
const vnode = h(islands[id][exportName], islandProps) as VNode;
|
||||||
if (key) vnode.key = key;
|
if (key) vnode.key = key;
|
||||||
vnodeStack.push(vnode);
|
vnodeStack.push(vnode);
|
||||||
}
|
}
|
||||||
@@ -510,7 +510,7 @@ function _walkInner(
|
|||||||
// Remove internal fresh key
|
// Remove internal fresh key
|
||||||
if (hasKey) sib.removeAttribute(DATA_KEY_ATTR);
|
if (hasKey) sib.removeAttribute(DATA_KEY_ATTR);
|
||||||
|
|
||||||
const vnode = h(sib.localName, newProps);
|
const vnode = h(sib.localName, newProps) as VNode;
|
||||||
addPropsChild(parentVNode, vnode);
|
addPropsChild(parentVNode, vnode);
|
||||||
vnodeStack.push(vnode);
|
vnodeStack.push(vnode);
|
||||||
} else {
|
} else {
|
||||||
@@ -621,7 +621,7 @@ function collectPartials(
|
|||||||
islands,
|
islands,
|
||||||
state[0] ?? [],
|
state[0] ?? [],
|
||||||
[],
|
[],
|
||||||
[h(Fragment, null)],
|
[h(Fragment, null) as VNode],
|
||||||
rootFrag,
|
rootFrag,
|
||||||
encounteredPartials,
|
encounteredPartials,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ export function setRenderState(state: RenderState | null): void {
|
|||||||
const supportsUnstableComments = renderToString(h(Fragment, {
|
const supportsUnstableComments = renderToString(h(Fragment, {
|
||||||
// @ts-ignore unstable features not supported in types
|
// @ts-ignore unstable features not supported in types
|
||||||
UNSTABLE_comment: "foo",
|
UNSTABLE_comment: "foo",
|
||||||
})) !== "";
|
}) as VNode) !== "";
|
||||||
|
|
||||||
if (!supportsUnstableComments) {
|
if (!supportsUnstableComments) {
|
||||||
console.warn(
|
console.warn(
|
||||||
@@ -347,7 +347,7 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const child = h(originalType, props);
|
const child = h(originalType, props) as VNode;
|
||||||
patched.add(child);
|
patched.add(child);
|
||||||
islandProps.push(props);
|
islandProps.push(props);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { RenderState } from "./state.ts";
|
import { RenderState } from "./state.ts";
|
||||||
import { setRenderState } from "./preact_hooks.ts";
|
import { setRenderState } from "./preact_hooks.ts";
|
||||||
import { renderToString } from "preact-render-to-string";
|
import { renderToString } from "preact-render-to-string";
|
||||||
import { Fragment, h, isValidElement, toChildArray, VNode } from "preact";
|
import {
|
||||||
|
ComponentType,
|
||||||
|
Fragment,
|
||||||
|
h,
|
||||||
|
isValidElement,
|
||||||
|
toChildArray,
|
||||||
|
VNode,
|
||||||
|
} from "preact";
|
||||||
import { HEAD_CONTEXT } from "../../runtime/head.ts";
|
import { HEAD_CONTEXT } from "../../runtime/head.ts";
|
||||||
import { CSP_CONTEXT } from "../../runtime/csp.ts";
|
import { CSP_CONTEXT } from "../../runtime/csp.ts";
|
||||||
|
|
||||||
@@ -13,12 +20,12 @@ export function renderHtml(state: RenderState) {
|
|||||||
const componentStack = state.componentStack;
|
const componentStack = state.componentStack;
|
||||||
try {
|
try {
|
||||||
const routeComponent = componentStack[componentStack.length - 1];
|
const routeComponent = componentStack[componentStack.length - 1];
|
||||||
let finalComp = h(routeComponent, state.routeOptions);
|
let finalComp = h(routeComponent, state.routeOptions) as VNode;
|
||||||
|
|
||||||
// Skip page component
|
// Skip page component
|
||||||
let i = componentStack.length - 1;
|
let i = componentStack.length - 1;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
const component = componentStack[i];
|
const component = componentStack[i] as ComponentType;
|
||||||
const curComp = finalComp;
|
const curComp = finalComp;
|
||||||
|
|
||||||
finalComp = h(component, {
|
finalComp = h(component, {
|
||||||
@@ -26,7 +33,8 @@ export function renderHtml(state: RenderState) {
|
|||||||
Component() {
|
Component() {
|
||||||
return curComp;
|
return curComp;
|
||||||
},
|
},
|
||||||
});
|
// deno-lint-ignore no-explicit-any
|
||||||
|
} as any) as VNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = h(
|
const app = h(
|
||||||
@@ -37,12 +45,12 @@ export function renderHtml(state: RenderState) {
|
|||||||
value: state.headVNodes,
|
value: state.headVNodes,
|
||||||
children: finalComp,
|
children: finalComp,
|
||||||
}),
|
}),
|
||||||
);
|
) as VNode;
|
||||||
|
|
||||||
let html = renderToString(app);
|
let html = renderToString(app);
|
||||||
|
|
||||||
for (const [id, children] of state.slots.entries()) {
|
for (const [id, children] of state.slots.entries()) {
|
||||||
const slotHtml = renderToString(h(Fragment, null, children));
|
const slotHtml = renderToString(h(Fragment, null, children) as VNode);
|
||||||
const templateId = id.replace(/:/g, "-");
|
const templateId = id.replace(/:/g, "-");
|
||||||
html += `<template id="${templateId}">${slotHtml}</template>`;
|
html += `<template id="${templateId}">${slotHtml}</template>`;
|
||||||
}
|
}
|
||||||
@@ -103,7 +111,7 @@ export function renderOuterDocument(
|
|||||||
h(
|
h(
|
||||||
"head",
|
"head",
|
||||||
docHead,
|
docHead,
|
||||||
!renderedHtmlTag ? h("meta", { charSet: "utf-8" }) : null,
|
!renderedHtmlTag ? h("meta", { charset: "utf-8" }) : null,
|
||||||
!renderedHtmlTag
|
!renderedHtmlTag
|
||||||
? (h("meta", {
|
? (h("meta", {
|
||||||
name: "viewport",
|
name: "viewport",
|
||||||
@@ -124,7 +132,7 @@ export function renderOuterDocument(
|
|||||||
...docBody,
|
...docBody,
|
||||||
dangerouslySetInnerHTML: { __html: opts.bodyHtml },
|
dangerouslySetInnerHTML: { __html: opts.bodyHtml },
|
||||||
}),
|
}),
|
||||||
);
|
) as VNode;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setRenderState(state);
|
setRenderState(state);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default async function App(req: Request, ctx: AppContext) {
|
|||||||
return (
|
return (
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0"
|
content="width=device-width, initial-scale=1.0"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default function App(
|
|||||||
return (
|
return (
|
||||||
<html lang={state.lang} class="html">
|
<html lang={state.lang} class="html">
|
||||||
<head class="head">
|
<head class="head">
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>fresh title</title>
|
<title>fresh title</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export default defineApp((res, ctx) => {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>test</title>
|
<title>test</title>
|
||||||
<link rel="stylesheet" href="/style.css" />
|
<link rel="stylesheet" href="/style.css" />
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default function AppLayout({ Component }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>fresh title</title>
|
<title>fresh title</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default function AppLayout({ Component }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>fresh title</title>
|
<title>fresh title</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export default function App({ Component }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html className="bg-slate-800">
|
<html className="bg-slate-800">
|
||||||
<head className="bg-slate-800">
|
<head className="bg-slate-800">
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>fresh-foo</title>
|
<title>fresh-foo</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ export default function App({ Component }: AppProps) {
|
|||||||
return (
|
return (
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>${basename(resolvedDirectory)}</title>
|
<title>${basename(resolvedDirectory)}</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user