Skip to content

Commit

Permalink
Merge branch 'canary' into arlyon/fix-some-to-resolved-in-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Dec 4, 2024
2 parents df98a66 + d19d26f commit 1a040e2
Show file tree
Hide file tree
Showing 127 changed files with 39,095 additions and 534 deletions.
12 changes: 10 additions & 2 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2578,8 +2578,16 @@ fn collect_idents_in_pat(pat: &Pat, idents: &mut Vec<Ident>) {
}

fn collect_decl_idents_in_stmt(stmt: &Stmt, idents: &mut Vec<Ident>) {
if let Stmt::Decl(Decl::Var(var)) = &stmt {
collect_idents_in_var_decls(&var.decls, idents);
if let Stmt::Decl(decl) = stmt {
match decl {
Decl::Var(var) => {
collect_idents_in_var_decls(&var.decls, idents);
}
Decl::Fn(fn_decl) => {
idents.push(fn_decl.ident.clone());
}
_ => {}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function createCachedFn(start) {
function fn() {
return start + Math.random()
}

return async () => {
'use cache'
return fn()
}
}

function createServerAction(start) {
function fn() {
return start + Math.random()
}

return async () => {
'use server'
console.log(fn())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* __next_internal_action_entry_do_not_use__ {"401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","c03128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "c03128060c414d59f8552e4788b846c0d2b7f74743", 1, async function([$$ACTION_ARG_0]) {
return $$ACTION_ARG_0();
});
function createCachedFn(start) {
function fn() {
return start + Math.random();
}
return $$RSC_SERVER_REF_1.bind(null, encryptActionBoundArgs("c03128060c414d59f8552e4788b846c0d2b7f74743", [
fn
]));
}
var $$RSC_SERVER_REF_1 = /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ registerServerReference($$RSC_SERVER_CACHE_0, "c03128060c414d59f8552e4788b846c0d2b7f74743", null);
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_2 = async function($$ACTION_CLOSURE_BOUND) {
var [$$ACTION_ARG_0] = await decryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", $$ACTION_CLOSURE_BOUND);
console.log($$ACTION_ARG_0());
};
function createServerAction(start) {
function fn() {
return start + Math.random();
}
return registerServerReference($$RSC_SERVER_ACTION_2, "401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", null).bind(null, encryptActionBoundArgs("401c36b06e398c97abe5d5d7ae8c672bfddf4e1b91", [
fn
]));
}
140 changes: 66 additions & 74 deletions docs/01-app/01-getting-started/04-images-and-fonts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The Next.js [`<Image>`](/docs/app/building-your-application/optimizing/images) c
- **Faster page loads:** Only loading images when they enter the viewport using native browser lazy loading, with optional blur-up placeholders.
- **Asset flexibility:** Resizing images on-demand, even images stored on remote servers.

To start using `<Image>`, first import it from `next/image` and render it within your component.
To start using `<Image>`, import it from `next/image` and render it within your component.

```tsx filename="app/page.tsx" switcher
import Image from 'next/image'
Expand Down Expand Up @@ -127,9 +127,7 @@ export default function Page() {
}
```

Since Next.js does not have access to remote files during the build process, you'll need to provide the [`width`](/docs/app/api-reference/components/image#width), [`height`](/docs/app/api-reference/components/image#height) and optional [`blurDataURL`](/docs/app/api-reference/components/image#blurdataurl) props manually.

> **Good to know:** The `width` and `height` attributes are used to infer the correct aspect ratio of image and avoid layout shift from the image loading in. The `width` and `height` do _not_ determine the rendered size of the image file.
Since Next.js does not have access to remote files during the build process, you'll need to provide the [`width`](/docs/app/api-reference/components/image#width), [`height`](/docs/app/api-reference/components/image#height) and optional [`blurDataURL`](/docs/app/api-reference/components/image#blurdataurl) props manually. The `width` and `height` attributes are used to infer the correct aspect ratio of image and avoid layout shift from the image loading in. But `width` and `height` do _not_ determine the rendered size of the image file.

Then, to safely allow images from remote servers, you need to define a list of supported URL patterns in `next.config.js`. Be as specific as possible to prevent malicious usage. For example, the following configuration will only allow images from a specific AWS S3 bucket:

Expand All @@ -144,6 +142,7 @@ const config: NextConfig = {
hostname: 's3.amazonaws.com',
port: '',
pathname: '/my-bucket/**',
search: '',
},
],
},
Expand All @@ -161,6 +160,7 @@ module.exports = {
hostname: 's3.amazonaws.com',
port: '',
pathname: '/my-bucket/**',
search: '',
},
],
},
Expand All @@ -175,14 +175,13 @@ The [`next/font`](/docs/app/api-reference/components/font) module automatically

It includes **built-in automatic self-hosting** for _any_ font file. This means you can optimally load web fonts with no layout shift.

To start using `next/font`, import it from `next/font/local` or `next/font/google` (depending on whether you're using a [local](#local-fonts) or [Google](#google-fonts) font), call it as a function with the appropriate options, and set the `className` of the element you want to apply the font to.
To start using `next/font`, import it from `next/font/local` or `next/font/google` (depending on whether you're using a [Google](#google-fonts) or [local](#local-fonts) font), call it as a function with the appropriate options, and set the `className` of the element you want to apply the font to.

```tsx filename="app/layout.tsx" switcher
import { Geist } from 'next/font/google'

const geist = Geist({
subsets: ['latin'],
display: 'swap',
})

export default function Layout({ children }: { children: React.ReactNode }) {
Expand All @@ -199,7 +198,6 @@ import { Geist } from 'next/font/google'

const geist = Geist({
subsets: ['latin'],
display: 'swap',
})

export default function Layout({ children }) {
Expand All @@ -211,16 +209,17 @@ export default function Layout({ children }) {
}
```

### Local fonts
### Google fonts

To use a local font, import `next/font/local` and specify the `src` of your local font file in the [`public` folder](#handling-static-assets).
You can automatically self-host any Google Font. Fonts are included in the deployment and served from the same domain as your deployment. **No requests are sent to Google by the browser.**

To start using a Google Font, import it from `next/font/google` as a function.

```tsx filename="app/layout.tsx" switcher
import localFont from 'next/font/local'
import { Inter } from 'next/font/google'

const myFont = localFont({
src: './my-font.woff2',
display: 'swap',
const inter = Inter({
subsets: ['latin'],
})

export default function RootLayout({
Expand All @@ -229,71 +228,37 @@ export default function RootLayout({
children: React.ReactNode
}) {
return (
<html lang="en" className={myFont.className}>
<html lang="en" className={inter.className}>
<body>{children}</body>
</html>
)
}
```

```jsx filename="app/layout.js" switcher
import localFont from 'next/font/local'
import { Inter } from 'next/font/google'

const myFont = localFont({
src: './my-font.woff2',
display: 'swap',
const inter = Inter({
subsets: ['latin'],
})

export default function RootLayout({ children }) {
return (
<html lang="en" className={myFont.className}>
<html lang="en" className={inter.className}>
<body>{children}</body>
</html>
)
}
```

If you want to use multiple files for a single font family, `src` can be an array:

```js
const roboto = localFont({
src: [
{
path: './Roboto-Regular.woff2',
weight: '400',
style: 'normal',
},
{
path: './Roboto-Italic.woff2',
weight: '400',
style: 'italic',
},
{
path: './Roboto-Bold.woff2',
weight: '700',
style: 'normal',
},
{
path: './Roboto-BoldItalic.woff2',
weight: '700',
style: 'italic',
},
],
})
```

### Google fonts

You can automatically self-host any Google Font. Fonts are included in the deployment and served from the same domain as your deployment. **No requests are sent to Google by the browser.**

To start using a Google Font, import it from `next/font/google` as a function.
We recommend using [variable fonts](https://fonts.google.com/variablefonts) for the best performance and flexibility. But if you can't use a variable font, you will **need to specify a weight**:

```tsx filename="app/layout.tsx" switcher
import { Inter } from 'next/font/google'
import { Roboto } from 'next/font/google'

const inter = Inter({
const roboto = Roboto({
weight: '400',
subsets: ['latin'],
display: 'swap',
})

export default function RootLayout({
Expand All @@ -302,39 +267,39 @@ export default function RootLayout({
children: React.ReactNode
}) {
return (
<html lang="en" className={inter.className}>
<html lang="en" className={roboto.className}>
<body>{children}</body>
</html>
)
}
```

```jsx filename="app/layout.js" switcher
import { Inter } from 'next/font/google'
import { Roboto } from 'next/font/google'

const inter = Inter({
const roboto = Roboto({
weight: '400',
subsets: ['latin'],
display: 'swap',
})

export default function RootLayout({ children }) {
return (
<html lang="en" className={inter.className}>
<html lang="en" className={roboto.className}>
<body>{children}</body>
</html>
)
}
```

We recommend using [variable fonts](https://fonts.google.com/variablefonts) for the best performance and flexibility. But if you can't use a variable font, you will **need to specify a weight**:
### Local fonts

To use a local font, import `next/font/local` and specify the `src` of your local font file in the [`public` folder](#handling-static-assets).

```tsx filename="app/layout.tsx" switcher
import { Roboto } from 'next/font/google'
import localFont from 'next/font/local'

const roboto = Roboto({
weight: '400',
subsets: ['latin'],
display: 'swap',
const myFont = localFont({
src: './my-font.woff2',
})

export default function RootLayout({
Expand All @@ -343,29 +308,56 @@ export default function RootLayout({
children: React.ReactNode
}) {
return (
<html lang="en" className={roboto.className}>
<html lang="en" className={myFont.className}>
<body>{children}</body>
</html>
)
}
```

```jsx filename="app/layout.js" switcher
import { Roboto } from 'next/font/google'
import localFont from 'next/font/local'

const roboto = Roboto({
weight: '400',
subsets: ['latin'],
display: 'swap',
const myFont = localFont({
src: './my-font.woff2',
})

export default function RootLayout({ children }) {
return (
<html lang="en" className={roboto.className}>
<html lang="en" className={myFont.className}>
<body>{children}</body>
</html>
)
}
```

If you want to use multiple files for a single font family, `src` can be an array:

```js
const roboto = localFont({
src: [
{
path: './Roboto-Regular.woff2',
weight: '400',
style: 'normal',
},
{
path: './Roboto-Italic.woff2',
weight: '400',
style: 'italic',
},
{
path: './Roboto-Bold.woff2',
weight: '700',
style: 'normal',
},
{
path: './Roboto-BoldItalic.woff2',
weight: '700',
style: 'italic',
},
],
})
```

Learn more about Font Optimization in the [API Reference](/docs/app/api-reference/components/font).
Loading

0 comments on commit 1a040e2

Please # to comment.