Skip to content

Commit

Permalink
Merge branch 'canary' into edge-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 11, 2024
2 parents d33d850 + 720641a commit 7dbb753
Show file tree
Hide file tree
Showing 31 changed files with 138 additions and 246 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type { NextPageWithLayout } from "./_app";
import Layout from "../components/layout";
import Sidebar from "../components/sidebar";

const About: NextPageWithLayout = () => {
export default function Home() {
return (
<section>
<h2>Layout Example (About)</h2>
<p>
This example adds a property <code>getLayout</code> to your page,
allowing you to return a React component for the layout. This allows you
to define the layout on a per-page basis. Since we're returning a
function, we can have complex nested layouts if desired.
You can define a layout by default exporting a React component from a
layout.js file. The component should accept a children prop that will be
populated with a child layout (if it exists) or a page during rendering.
</p>
<p>
When navigating between pages, we want to persist page state (input
Expand All @@ -31,15 +26,4 @@ const About: NextPageWithLayout = () => {
</p>
</section>
);
};

export default About;

About.getLayout = function getLayout(page: React.ReactElement) {
return (
<Layout>
<Sidebar />
{page}
</Layout>
);
};
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type { NextPageWithLayout } from "./_app";
import Layout from "../components/layout";
import Sidebar from "../components/sidebar";

const Contact: NextPageWithLayout = () => {
export default function Home() {
return (
<section>
<h2>Layout Example (Contact)</h2>
<p>
This example adds a property <code>getLayout</code> to your page,
allowing you to return a React component for the layout. This allows you
to define the layout on a per-page basis. Since we're returning a
function, we can have complex nested layouts if desired.
You can define a layout by default exporting a React component from a
layout.js file. The component should accept a children prop that will be
populated with a child layout (if it exists) or a page during rendering.
</p>
<p>
When navigating between pages, we want to persist page state (input
Expand All @@ -31,15 +26,4 @@ const Contact: NextPageWithLayout = () => {
</p>
</section>
);
};

export default Contact;

Contact.getLayout = function getLayout(page: React.ReactElement) {
return (
<Layout>
<Sidebar />
{page}
</Layout>
);
};
}
23 changes: 23 additions & 0 deletions examples/layout-component/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Sidebar from "./_components/sidebar";
import styles from "./layout.module.css";

export const metadata = {
title: "Layouts Example",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>
<main className={styles.main}>
<Sidebar />
{children}
</main>
</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type { NextPageWithLayout } from "./_app";
import Layout from "../components/layout";
import Sidebar from "../components/sidebar";

const Index: NextPageWithLayout = () => {
export default function Home() {
return (
<section>
<h2>Layout Example (Index)</h2>
<p>
This example adds a property <code>getLayout</code> to your page,
allowing you to return a React component for the layout. This allows you
to define the layout on a per-page basis. Since we're returning a
function, we can have complex nested layouts if desired.
You can define a layout by default exporting a React component from a
layout.js file. The component should accept a children prop that will be
populated with a child layout (if it exists) or a page during rendering.
</p>
<p>
When navigating between pages, we want to persist page state (input
Expand All @@ -31,15 +26,4 @@ const Index: NextPageWithLayout = () => {
</p>
</section>
);
};

export default Index;

Index.getLayout = function getLayout(page: React.ReactElement) {
return (
<Layout>
<Sidebar />
{page}
</Layout>
);
};
}
17 changes: 0 additions & 17 deletions examples/layout-component/components/layout.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions examples/layout-component/pages/_app.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion examples/redirects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This example shows how to use [redirects in Next.js](https://nextjs.org/docs/api-reference/next.config.js/redirects) to redirect an incoming request path to a different destination path.

The index page ([`pages/index.tsx`](pages/index.tsx)) has a list of links that match the redirects defined in [`next.config.js`](next.config.js). Run or deploy the app to see how it works!
The index page ([`app/page.tsx`](app/page.tsx)) has a list of links that match the redirects defined in [`next.config.js`](next.config.js). Run or deploy the app to see how it works!

## Deploy your own

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styles from "../styles.module.css";
import styles from "../../styles.module.css";

type CodeProps = {
children: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from "next/link";
import styles from "../styles.module.css";
import styles from "../../styles.module.css";

export default function About() {
return (
Expand Down
16 changes: 16 additions & 0 deletions examples/redirects/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const metadata = {
title: "Next.js",
description: "Generated by Next.js",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
27 changes: 27 additions & 0 deletions examples/redirects/app/news/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";
import { usePathname } from "next/navigation";
import Link from "next/link";
import styles from "../../../styles.module.css";
import Code from "../../_components/Code";

export default function News({ params }: Params) {
const pathname = usePathname();
return (
<div className={styles.container}>
<div className={styles.card}>
<h1>Path: {pathname}</h1>
<hr className={styles.hr} />
<p>
The query <Code>slug</Code> for this page is:{" "}
<Code>{JSON.stringify(params.slug)}</Code>
</p>
<Link href="/">&larr; Back home</Link>
</div>
</div>
);
}
type Params = {
params: {
slug: string;
};
};
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import styles from "../styles.module.css";
import Link from "next/link";
import Code from "../components/Code";
import Code from "./_components/Code";

export default function Index() {
export default function Home() {
return (
<div className={styles.container}>
<div className={styles.card}>
<h1>Redirects with Next.js</h1>
<h1 className="text-white">Redirects with Next.js</h1>
<hr className={styles.hr} />
<p>
The links below are{" "}
The links below are custom
<Link
href="https://nextjs.org/docs/api-reference/next.config.js/redirects"
legacyBehavior
>
<>
custom <Code>redirects</Code>
<Code>redirects</Code>
</>
</Link>{" "}
that redirect an incoming request path to a different destination
Expand Down
25 changes: 0 additions & 25 deletions examples/redirects/pages/news/[...slug].tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ impl Fold for OptimizeBarrel {
span: DUMMY_SP,
src: Box::new(Str {
span: DUMMY_SP,
value: format!("__barrel_optimize__?names=__PLACEHOLDER__!=!{}", src)
.into(),
value: format!("__barrel_optimize__?names=__PLACEHOLDER__!=!{src}").into(),
raw: None,
}),
with: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Fold for PageConfig {
type_ann: None,
}),
init: Some(Box::new(Expr::Lit(Lit::Str(Str {
value: format!("{} {}", STRING_LITERAL_DROP_BUNDLE, timestamp).into(),
value: format!("{STRING_LITERAL_DROP_BUNDLE} {timestamp}").into(),
span: DUMMY_SP,
raw: None,
})))),
Expand Down Expand Up @@ -171,8 +171,8 @@ impl Fold for PageConfig {
impl PageConfig {
fn handle_error(&mut self, details: &str, span: Span) {
if self.is_page_file {
let message = format!("Invalid page config export found. {} \
See: https://nextjs.org/docs/messages/invalid-page-config", details);
let message = format!("Invalid page config export found. {details} \
See: https://nextjs.org/docs/messages/invalid-page-config");
HANDLER.with(|handler| handler.struct_span_err(span, &message).emit());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
Some(elem) => {
if elem.spread.is_some() {
return Some(Const::Unsupported(format!(
"Unsupported spread operator in the Array Expression at \"{}\"",
id
"Unsupported spread operator in the Array Expression at \"{id}\""
)));
}

Expand Down Expand Up @@ -139,21 +138,19 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
PropName::Str(s) => s.value.as_ref(),
_ => {
return Some(Const::Unsupported(format!(
"Unsupported key type in the Object Expression at \"{}\"",
id
"Unsupported key type in the Object Expression at \"{id}\""
)))
}
},
&kv.value,
),
_ => {
return Some(Const::Unsupported(format!(
"Unsupported spread operator in the Object Expression at \"{}\"",
id
"Unsupported spread operator in the Object Expression at \"{id}\""
)))
}
};
let new_value = extract_value(ctx, value, format!("{}.{}", id, key));
let new_value = extract_value(ctx, value, format!("{id}.{key}"));
if let Some(Const::Unsupported(msg)) = new_value {
return Some(Const::Unsupported(msg));
}
Expand All @@ -169,8 +166,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
// [TODO] should we add support for `${'e'}d${'g'}'e'`?
if !tpl.exprs.is_empty() {
Some(Const::Unsupported(format!(
"Unsupported template literal with expressions at \"{}\".",
id
"Unsupported template literal with expressions at \"{id}\"."
)))
} else {
Some(
Expand All @@ -196,15 +192,13 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
))
})
.unwrap_or(Const::Unsupported(format!(
"Unsupported node type at \"{}\"",
id
"Unsupported node type at \"{id}\""
))),
)
}
}
_ => Some(Const::Unsupported(format!(
"Unsupported node type at \"{}\"",
id
"Unsupported node type at \"{id}\""
))),
}
}
Loading

0 comments on commit 7dbb753

Please sign in to comment.