Skip to content

Commit 592c666

Browse files
sergiodxatimneutkens
authored andcommitted
[example] Progressive rendered application (vercel#998)
* [add] example of a progressive rendered app * [update] remove extra blank line * [update] fix typo * [update] more use cases * [update] example link * Update README.md * [update] next.js dependency version * [update] fix readme typos
1 parent 267b74b commit 592c666

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

examples/progressive-render/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Example app implementing progressive server-side render
2+
3+
## How to use
4+
5+
Download the example [or clone the repo](https://github.com/zeit/next.js):
6+
7+
```bash
8+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/progressive-render
9+
cd progressive-render
10+
```
11+
12+
Install it and run:
13+
14+
```bash
15+
npm install
16+
npm run dev
17+
```
18+
19+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
20+
21+
```bash
22+
now
23+
```
24+
25+
## The idea behind the example
26+
27+
Sometimes you want to **not** server render some parts of your application. That can be third party components without server render capabilities, components that depends on `window` and other browser only APIs or just because that content isn't important enough for the user (eg. below the fold content).
28+
29+
In that case you can wrap the component in `react-no-ssr` which will only render the component client-side.
30+
31+
This example features:
32+
33+
* An app with a component that must only be rendered in the client
34+
* A loading component that will be displayed before rendering the client-only component
35+
36+
**Example**: https://progressive-render-raceuevkqw.now.sh/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
3+
export default () => (
4+
<div>
5+
<h3>Loading...</h3>
6+
<style jsx>{`
7+
div {
8+
align-items: center;
9+
display: flex;
10+
height: 50vh;
11+
justify-content: center;
12+
}
13+
`}</style>
14+
</div>
15+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "progressive-render",
3+
"scripts": {
4+
"dev": "next",
5+
"build": "next build",
6+
"start": "next start"
7+
},
8+
"dependencies": {
9+
"next": "latest",
10+
"react-no-ssr": "1.1.0"
11+
}
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import NoSSR from 'react-no-ssr'
3+
import Loading from '../components/Loading'
4+
5+
export default () => (
6+
<main>
7+
<section>
8+
<h1>
9+
This section is server-side rendered.
10+
</h1>
11+
</section>
12+
13+
<NoSSR onSSR={<Loading />}>
14+
<section>
15+
<h2>
16+
This section is <em>only</em> client-side rendered.
17+
</h2>
18+
</section>
19+
</NoSSR>
20+
21+
<style jsx>{`
22+
section {
23+
align-items: center;
24+
display: flex;
25+
height: 50vh;
26+
justify-content: center;
27+
}
28+
`}</style>
29+
</main>
30+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy