chore: release 1.5.0 (#1899)
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
---
|
||||
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() {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
@@ -1,128 +0,0 @@
|
||||
---
|
||||
description: |
|
||||
New versions of Fresh are regularly released. This page explains how to update your project.
|
||||
---
|
||||
|
||||
Fresh consists of multiple pieces which are independently versioned and
|
||||
released.
|
||||
|
||||
- Fresh (https://deno.land/x/fresh)
|
||||
- Preact (https://esm.sh/preact)
|
||||
- preact-render-to-string (https://esm.sh/preact-render-to-string)
|
||||
|
||||
Some plugins also have their own dependencies that can be updated independently.
|
||||
|
||||
- Twind (https://esm.sh/twind) (for the twind plugin)
|
||||
|
||||
For the most part these pieces can be updated independently. Certain versions of
|
||||
Fresh may require a minimum version of a given dependency. This is documented
|
||||
below.
|
||||
|
||||
| Fresh version | Preact | preact-render-to-string | Deno |
|
||||
| ------------- | ----------------- | ----------------------- | --------- |
|
||||
| 1.0.0-1.0.2 | >=10.8.1 <11.0.0 | >=5.2.0 <6.0.0 | >= 1.23.0 |
|
||||
| 1.1.0-1.1.5 | >=10.8.1 <11.0.0 | >=5.2.0 <6.0.0 | >= 1.25.0 |
|
||||
| 1.2.0 | >=10.15.0 <11.0.0 | >=6.1.0 | >= 1.25.0 |
|
||||
|
||||
## Updating dependencies
|
||||
|
||||
To update your dependencies, you have two options:
|
||||
|
||||
- Run the Fresh updater to update your project dependencies.
|
||||
- Manually update the dependency versions in your `deno.json` file.
|
||||
|
||||
### Auto updater
|
||||
|
||||
The auto updater is a command line tool that will update your project's
|
||||
`deno.json` file to the latest versions of Fresh and its dependencies. It may
|
||||
also contain code mods for your project that will update your code to the latest
|
||||
recommended patterns for Fresh projects.
|
||||
|
||||
To run the auto updater, run the following command from the root of your
|
||||
project:
|
||||
|
||||
```sh Terminal
|
||||
$ deno run -A -r https://fresh.deno.dev/update
|
||||
```
|
||||
|
||||
You will be prompted to confirm the changes that will be made to your project.
|
||||
|
||||
### Manual update
|
||||
|
||||
To manually update your project's dependencies, you can edit the `deno.json`
|
||||
file in the root of your projects directory. Dependency versions are encoded
|
||||
into the URLs in this file. For example, here is how to update a project from
|
||||
Fresh 1.0.2 to 1.1.3, and update Preact to the latest version:
|
||||
|
||||
```diff deno.json
|
||||
{
|
||||
"imports": {
|
||||
- "$fresh/": "https://deno.land/x/fresh@1.0.2/",
|
||||
+ "$fresh/": "https://deno.land/x/fresh@1.1.5/",
|
||||
|
||||
- "preact": "https://esm.sh/preact@10.8.1",
|
||||
- "preact/": "https://esm.sh/preact@10.8.1/",
|
||||
+ "preact": "https://esm.sh/preact@10.11.0",
|
||||
+ "preact/": "https://esm.sh/preact@10.11.0/",
|
||||
|
||||
- "preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.0",
|
||||
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.1.0",
|
||||
|
||||
"twind": "https://esm.sh/twind@0.16.17",
|
||||
"twind/": "https://esm.sh/twind@0.16.17/"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Automatic update checks
|
||||
|
||||
Fresh will periodically check if a new Fresh version is available if it's
|
||||
running outside of CI. This happens once per day and can be disabled by setting
|
||||
the `FRESH_NO_UPDATE_CHECK=true` environment variable.
|
||||
|
||||
## Code mods
|
||||
|
||||
Code mods are small scripts that can be run to update your project's code to
|
||||
match the latest recommended patterns for Fresh projects. Code mods can be run
|
||||
through the auto updater. Sometimes the code mod can not cover all cases, so you
|
||||
may need to manually update some code. This section explains the code mods
|
||||
currently available.
|
||||
|
||||
### Classical JSX -> Automatic JSX
|
||||
|
||||
> This code mod is only available in Fresh 1.1.0 and above.
|
||||
|
||||
The classical JSX transform that relies on a `/** @jsx h */` pragma is no longer
|
||||
the recommended way to use JSX in Fresh projects. Instead, starting with version
|
||||
1.1.0, Fresh projects should use the automatic JSX transform that requires no
|
||||
JSX pragma or preact import.
|
||||
|
||||
```diff
|
||||
- /** @jsx h */
|
||||
- import { h } from "preact";
|
||||
|
||||
export default function Page() {
|
||||
return <div>Hello world!</div>;
|
||||
}
|
||||
```
|
||||
|
||||
This code mod will update your deno.json file to include the relevant compiler
|
||||
options to enable the automatic JSX transform. It will then go through your
|
||||
project and remove any `/** @jsx h */` pragmas and `import { h } from "preact"`
|
||||
statements.
|
||||
|
||||
### Classic twind -> Twind plugin
|
||||
|
||||
> This code mod is only available in Fresh 1.1.0 and above.
|
||||
|
||||
Fresh version 1.1.0 introduced a new plugin for using twind with Fresh. This
|
||||
plugin is much nicer to use than the raw twind integration that was previously
|
||||
available.
|
||||
|
||||
This code mod will update your project to use the new twind plugin. It will
|
||||
update your `main.ts` file to import the twind plugin and add it to the plugins
|
||||
array. It will also update your files to remove many unnecessary uses of the
|
||||
`tw` function, and remove unnecessary twind imports. While the code mod can
|
||||
handle most cases, you may need to manually update some code. Additionally you
|
||||
will need to manually update your `twind.config.ts` if you use a custom
|
||||
configuration.
|
||||
@@ -1,79 +0,0 @@
|
||||
---
|
||||
description: |
|
||||
Add components like <title> or <meta> to a <head> tag using Fresh's <Head> component.
|
||||
---
|
||||
|
||||
We can use the `<Head />` component in `$fresh/runtime.ts` to add elements as
|
||||
children of the `<head>` element. By adding elements as children of Fresh's
|
||||
`<Head />` tag, these automatically get injected into the `<head>` element of
|
||||
the web page. Some uses include:
|
||||
|
||||
- Setting the document title using `<title>`
|
||||
- Specifying page metadata using `<meta>`
|
||||
- Linking to resources like stylesheets using `<link>`
|
||||
- Including third-party JavaScript code using `<script>`
|
||||
|
||||
```tsx routes/index.tsx
|
||||
import { Head } from "$fresh/runtime.ts";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Fresh App</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="This is a brief description of Fresh"
|
||||
/>
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<script src="script.js"></script>
|
||||
</Head>
|
||||
<div class="p-4 mx-auto max-w-screen-md">
|
||||
<h1>Hello World</h1>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Avoiding duplicate tags
|
||||
|
||||
You might end up with duplicate tags, when multiple `<Head />` components are
|
||||
rendered on the same page. This can happen when you render `<Head />` in a route
|
||||
and another `<Head />` in another component for example.
|
||||
|
||||
```tsx
|
||||
// routes/page-a.tsx
|
||||
<Head>
|
||||
<meta name="og:title" content="This is a title" />
|
||||
</Head>
|
||||
|
||||
// components/MyTitle.tsx
|
||||
<Head>
|
||||
<meta name="og:title" content="Other title" />
|
||||
</Head>
|
||||
```
|
||||
|
||||
To ensure that the tag is not duplicated, Fresh supports setting the `key` prop.
|
||||
By giving matching elements the same `key` prop, only the last one will be
|
||||
rendered.
|
||||
|
||||
```diff
|
||||
// routes/page-a.tsx
|
||||
<Head>
|
||||
- <meta name="og:title" content="This is a title" />
|
||||
+ <meta name="og:title" content="This is a title" key="title" />
|
||||
</Head>
|
||||
|
||||
// components/MyTitle.tsx
|
||||
<Head>
|
||||
- <meta name="og:title" content="Other title" />
|
||||
+ <meta name="og:title" content="Other title" key="title" />
|
||||
</Head>
|
||||
```
|
||||
|
||||
The rendered page will only include the `<meta>`-tag with `"Other title"`.
|
||||
|
||||
> [info]: The `<title>`-tag is automatically deduplicated, even without a `key`
|
||||
> prop.
|
||||
@@ -42,7 +42,7 @@ To run the auto updater, run the following command from the root of your
|
||||
project:
|
||||
|
||||
```sh Terminal
|
||||
$ deno run -A -r https://fresh.deno.dev/update .
|
||||
$ deno run -A -r https://fresh.deno.dev/update
|
||||
```
|
||||
|
||||
You will be prompted to confirm the changes that will be made to your project.
|
||||
|
||||
@@ -36,3 +36,44 @@ export default function Home() {
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Avoiding duplicate tags
|
||||
|
||||
You might end up with duplicate tags, when multiple `<Head />` components are
|
||||
rendered on the same page. This can happen when you render `<Head />` in a route
|
||||
and another `<Head />` in another component for example.
|
||||
|
||||
```tsx
|
||||
// routes/page-a.tsx
|
||||
<Head>
|
||||
<meta name="og:title" content="This is a title" />
|
||||
</Head>
|
||||
|
||||
// components/MyTitle.tsx
|
||||
<Head>
|
||||
<meta name="og:title" content="Other title" />
|
||||
</Head>
|
||||
```
|
||||
|
||||
To ensure that the tag is not duplicated, Fresh supports setting the `key` prop.
|
||||
By giving matching elements the same `key` prop, only the last one will be
|
||||
rendered.
|
||||
|
||||
```diff
|
||||
// routes/page-a.tsx
|
||||
<Head>
|
||||
- <meta name="og:title" content="This is a title" />
|
||||
+ <meta name="og:title" content="This is a title" key="title" />
|
||||
</Head>
|
||||
|
||||
// components/MyTitle.tsx
|
||||
<Head>
|
||||
- <meta name="og:title" content="Other title" />
|
||||
+ <meta name="og:title" content="Other title" key="title" />
|
||||
</Head>
|
||||
```
|
||||
|
||||
The rendered page will only include the `<meta>`-tag with `"Other title"`.
|
||||
|
||||
> [info]: The `<title>`-tag is automatically deduplicated, even without a `key`
|
||||
> prop.
|
||||
|
||||
+7
-5
@@ -48,19 +48,19 @@ const toc: RawTableOfContents = {
|
||||
["server-components", "Server Components", "link:latest"],
|
||||
["routing", "Routing", "link:latest"],
|
||||
["routes", "Routes", "link:latest"],
|
||||
["app-wrapper", "App wrapper", "link:canary"],
|
||||
["app-wrapper", "App wrapper", "link:latest"],
|
||||
["layouts", "Layouts", "link:latest"],
|
||||
["forms", "Forms", "link:latest"],
|
||||
["islands", "Interactive islands", "link:latest"],
|
||||
["static-files", "Static files", "link:latest"],
|
||||
["middleware", "Middlewares", "link:latest"],
|
||||
["error-pages", "Error pages", "link:latest"],
|
||||
["partials", "Partials", "link:canary"],
|
||||
["partials", "Partials", "link:latest"],
|
||||
["data-fetching", "Data fetching", "link:latest"],
|
||||
["ahead-of-time-builds", "Ahead-of-time Builds", "link:latest"],
|
||||
["deployment", "Deployment", "link:latest"],
|
||||
["plugins", "Plugins", "link:latest"],
|
||||
["updating", "Updating Fresh", "link:canary"],
|
||||
["updating", "Updating Fresh", "link:latest"],
|
||||
["server-configuration", "Server configuration", "link:latest"],
|
||||
],
|
||||
},
|
||||
@@ -72,7 +72,7 @@ const toc: RawTableOfContents = {
|
||||
title: "Examples",
|
||||
link: "latest",
|
||||
pages: [
|
||||
["modifying-the-head", "Modifying the <head>", "link:canary"],
|
||||
["modifying-the-head", "Modifying the <head>", "link:latest"],
|
||||
["writing-tests", "Writing tests", "link:latest"],
|
||||
[
|
||||
"changing-the-src-dir",
|
||||
@@ -97,7 +97,7 @@ const toc: RawTableOfContents = {
|
||||
],
|
||||
["using-deno-kv-oauth", "Using Deno KV OAuth", "link:latest"],
|
||||
["using-csp", "Using CSP", "link:latest"],
|
||||
["active-links", "Styling active links", "link:canary"],
|
||||
["active-links", "Styling active links", "link:latest"],
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -136,6 +136,7 @@ const toc: RawTableOfContents = {
|
||||
["static-files", "Static files"],
|
||||
["middleware", "Middlewares"],
|
||||
["error-pages", "Error pages"],
|
||||
["partials", "Partials"],
|
||||
["data-fetching", "Data fetching"],
|
||||
["ahead-of-time-builds", "Ahead-of-time Builds"],
|
||||
["deployment", "Deployment"],
|
||||
@@ -163,6 +164,7 @@ const toc: RawTableOfContents = {
|
||||
["sharing-state-between-islands", "Sharing state between islands"],
|
||||
["using-deno-kv-oauth", "Using Deno KV OAuth"],
|
||||
["using-csp", "Using CSP"],
|
||||
["active-links", "Styling active links"],
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user