Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-orsini committed Sep 2, 2022
0 parents commit ee09d20
Show file tree
Hide file tree
Showing 26 changed files with 2,809 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry "https://registry.npmjs.org/"
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
16 changes: 16 additions & 0 deletions app/(examples)/happy/[duration]/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Loading = () => {
return (
<div className="lds-roller">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
);
};

export default Loading;
16 changes: 16 additions & 0 deletions app/(examples)/happy/[duration]/page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import durations from "../../../../util/durations";

export const getServerSideProps = async (context) => {
const { duration } = context.params;

// artificial delay
await new Promise((resolve) => setTimeout(resolve, durations[duration]));

return {
props: { wait: durations[duration] },
};
};

export default function Page({ children, wait }) {
return <p> Waited {wait / 1000} seconds</p>;
}
10 changes: 10 additions & 0 deletions app/(examples)/happy/layout.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const HappyWithLoadingLayout = ({ children }) => {
return (
<>
<p>Happy Path With Loading</p>
<div style={{ textAlign: "center" }}>{children}</div>
</>
);
};

export default HappyWithLoadingLayout;
5 changes: 5 additions & 0 deletions app/(examples)/happy/page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const HappyPage = ({ children }) => {
return <p>Explore the Happy Path!</p>;
};

export default HappyPage;
28 changes: 28 additions & 0 deletions app/(examples)/layout.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import SubNav from "../../components/sub-nav.client";

const ExamplesLayout = ({ children }) => {
return (
<>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
}}
>
<SubNav />
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
}}
>
{children}
</div>
</div>
</>
);
};

export default ExamplesLayout;
5 changes: 5 additions & 0 deletions app/(examples)/sad/[duration]/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Loading = () => {
<> Loading</>;
};

export default Loading;
16 changes: 16 additions & 0 deletions app/(examples)/sad/[duration]/page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import durations from "../../../../util/durations";

export const getServerSideProps = async (context) => {
const { duration } = context.params;

// artificial delay
await new Promise((resolve) => setTimeout(resolve, durations[duration]));

return {
props: { wait: durations[duration] },
};
};

export default function Page({ children, wait }) {
return <p> Waited {wait / 1000} seconds</p>;
}
10 changes: 10 additions & 0 deletions app/(examples)/sad/layout.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const SadLayout = ({ children }) => {
return (
<>
<p>Sad Path</p>
<div style={{ textAlign: "center" }}>{children}</div>
</>
);
};

export default SadLayout;
5 changes: 5 additions & 0 deletions app/(examples)/sad/page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SadPage = ({ children }) => {
return <p>Explore the Sad Path!</p>;
};

export default SadPage;
22 changes: 22 additions & 0 deletions app/layout.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import "../styles/globals.css";
import TopNav from "../components/nav.client";

export default function RootLayout({ children }) {
return (
<html>
<head>
<title>RSC Layout Streaming MVR</title>
</head>

<body>
<div>
<div>
<TopNav />
</div>
<div style={{ padding: "20px 100px" }}>{children}</div>
</div>
</body>
</html>
);
}
26 changes: 26 additions & 0 deletions app/page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default function Page() {
return (
<div style={{ padding: "20px" }}>
<h3>RSC / Layouts Loading Examples </h3>
<p> Description </p>
<p>
Each path has nested layouts which use artificial delays to simulate a
server component waiting for data fetch. Each path includes multiple
delay options for 1, 5 and 10 seconds.
</p>
<p>Happy Path</p>
<ul>
<li>loading.js used</li>
<li>Initial page load streams content</li>
</ul>
<p>Sad Path</p>
<ul>
<li>loading.js not used</li>
<li>
Initial page load waits for delay, does not stream rest of page first
</li>
<li>No client or server side logs indicating incorrect setup</li>
</ul>
</div>
);
}
19 changes: 19 additions & 0 deletions components/nav.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Link from "next/link";

const Nav = () => (
<>
<div style={{ display: "flex", justifyContent: "center" }}>
<div style={{ display: "flex", flexDirection: "column" }}>
<h2 style={{ textAlign: "center" }}>RSC Streaming Loading MVR</h2>

<div style={{ display: "flex", flexDirection: "row" }}>
<Link href="/">Home</Link>
<Link href="/happy">Happy Loading Path</Link>
<Link href="/sad">Sad Path</Link>
</div>
</div>
</div>
</>
);

export default Nav;
34 changes: 34 additions & 0 deletions components/sub-nav.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Link from "next/link";
import durations from "../util/durations";
import { useState } from "react";
import { usePathname } from "next/dist/client/components/hooks-client";

const SubNav = () => {
const [count, setCount] = useState(0);

const pathname = usePathname();

// this is trash but I'm too lazy to fix it
const basePath = pathname.includes("happy") ? "happy" : "sad";

return (
<>
<div style={{ display: "flex", flexDirection: "row" }}>
{Object.keys(durations).map((duration) => (
<Link
key={duration}
className="subnav"
href={`/${basePath}/${duration}`}
>
{duration}
</Link>
))}
<button onClick={() => setCount((curCount) => curCount + 1)}>
Clicks: {count}
</button>
</div>
</>
);
};

export default SubNav;
24 changes: 24 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
experimental: {
// Required:
appDir: true,
serverComponents: true,
// Recommended for new `<Link>` and `<Image>` behavior
// Enables `<Link>` without `<a>`. When migrating an existing app use the codemod as outlined here: https://github.com/vercel/next.js/pull/36436
newNextLinkBehavior: true,
// Enables `next/future/image`
images: {
allowFutureImage: true,
},
// Recommended, will be the default in the next major version:
// Enable browserslist handling, which is required for legacyBrowsers: false
browsersListForSwc: true,
// Change the default compilation output to ESModules compatible browsers
legacyBrowsers: false,
},
};

module.exports = nextConfig;
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "rsc-next-loading-mvr",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@fontsource/roboto": "^4.5.8",
"@mui/material": "^5.10.3",
"next": "^12.2.6-canary.8",
"react": "^0.0.0-experimental-9ff738f53-20220826",
"react-dom": "^0.0.0-experimental-9ff738f53-20220826"
},
"devDependencies": {
"eslint": "8.23.0",
"eslint-config-next": "12.2.5"
}
}
Empty file added pages/.gitkeep
Empty file.
Binary file added public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ee09d20

Please sign in to comment.