• Stars
    star
    4,242
  • Rank 10,189 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Demo app of React Server Components.

React Server Components Demo

What is this?

This is a demo app built with Server Components, an experimental React feature. We strongly recommend watching our talk introducing Server Components before exploring this demo. The talk includes a walkthrough of the demo code and highlights key points of how Server Components work and what features they provide.

Update (March 2023): This demo has been updated to match the latest conventions.

When will I be able to use this?

Server Components are an experimental feature and are not ready for adoption. For now, we recommend experimenting with Server Components via this demo app. Use this in your projects at your own risk.

Should I use this demo for benchmarks?

If you use this demo to compare React Server Components to the framework of your choice, keep this in mind:

  • This demo doesn’t have server rendering. Server Components are a separate (but complementary) technology from Server Rendering (SSR). Server Components let you run some of your components purely on the server. SSR, on the other hand, lets you generate HTML before any JavaScript loads. This demo only shows Server Components, and not SSR. Because it doesn't have SSR, the initial page load in this demo has a client-server network waterfall, and will be much slower than any SSR framework. However, Server Components are meant to be integrated together with SSR, and they will be in a future release.
  • This demo doesn’t have an efficient bundling strategy. When you use Server Components, a bundler plugin will automatically split the client JS bundle. However, the way it's currently being split is not necessarily optimal. We are investigating more efficient ways to split the bundles, but they are out of scope of this demo.
  • This demo doesn’t have partial refetching. Currently, when you click on different “notes”, the entire app shell is refetched from the server. However, that’s not ideal: for example, it’s unnecessary to refetch the sidebar content if all that changed is the inner content of the right pane. Partial refetching is an open area of research and we don’t yet know how exactly it will work.

This demo is provided “as is” to show the parts that are ready for experimentation. It is not intended to reflect the performance characteristics of a real app driven by a future stable release of Server Components.

Setup

You will need to have Node 18 LTS in order to run this demo. (If you use nvm, run nvm i before running npm install to install the recommended Node version.)

npm install --legacy-peer-deps
npm start

(Or npm run start:prod for a production build.)

Then open http://localhost:4000.

The app won't work until you set up the database, as described below.

Setup with Docker (optional)

You can also start dev build of the app by using docker-compose.

⚠️ This is completely optional, and is only for people who prefer Docker to global installs!

If you prefer Docker, make sure you have docker and docker-compose installed then run:

docker-compose up

Running seed script

1. Run containers in the detached mode

docker-compose up -d

2. Run seed script

docker-compose exec notes-app npm run seed

If you'd rather not use Docker, skip this section and continue below.

DB Setup

This demo uses Postgres. First, follow its installation link for your platform.

Alternatively, you can check out this fork which will let you run the demo app without needing a database. However, you won't be able to execute SQL queries (but fetch should still work). There is also another fork that uses Prisma with SQLite, so it doesn't require additional setup.

The below example will set up the database for this app, assuming that you have a UNIX-like platform:

Step 1. Create the Database

psql postgres

CREATE DATABASE notesapi;
CREATE ROLE notesadmin WITH LOGIN PASSWORD 'password';
ALTER ROLE notesadmin WITH SUPERUSER;
ALTER DATABASE notesapi OWNER TO notesadmin;
\q

Step 2. Connect to the Database

psql -d postgres -U notesadmin;

\c notesapi

DROP TABLE IF EXISTS notes;
CREATE TABLE notes (
  id SERIAL PRIMARY KEY,
  created_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL,
  title TEXT,
  body TEXT
);

\q

Step 3. Run the seed script

Finally, run npm run seed to populate some data.

And you're done!

Notes about this app

The demo is a note-taking app called React Notes. It consists of a few major parts:

  • It uses a Webpack plugin (not defined in this repo) that allows us to only include client components in build artifacts
  • An Express server that:
    • Serves API endpoints used in the app
    • Renders Server Components into a special format that we can read on the client
  • A React app containing Server and Client components used to build React Notes

This demo is built on top of our Webpack plugin, but this is not how we envision using Server Components when they are stable. They are intended to be used in a framework that supports server rendering — for example, in Next.js. This is an early demo -- the real integration will be developed in the coming months. Learn more in the announcement post.

Interesting things to try

  • Expand note(s) by hovering over the note in the sidebar, and clicking the expand/collapse toggle. Next, create or delete a note. What happens to the expanded notes?
  • Change a note's title while editing, and notice how editing an existing item animates in the sidebar. What happens if you edit a note in the middle of the list?
  • Search for any title. With the search text still in the search input, create a new note with a title matching the search text. What happens?
  • Search while on Slow 3G, observe the inline loading indicator.
  • Switch between two notes back and forth. Observe we don't send new responses next time we switch them again.
  • Uncomment the await fetch('http://localhost:4000/sleep/....') call in Note.js or NoteList.js to introduce an artificial delay and trigger Suspense.
    • If you only uncomment it in Note.js, you'll see the fallback every time you open a note.
    • If you only uncomment it in NoteList.js, you'll see the list fallback on first page load.
    • If you uncomment it in both, it won't be very interesting because we have nothing new to show until they both respond.
  • Add a new Server Component and place it above the search bar in App.js. Import db from db.js and use await db.query() from it to get the number of notes. Oberserve what happens when you add or delete a note.

You can watch a recorded walkthrough of all these demo points here with timestamps. (Note: this recording is slightly outdated because the repository has been updated to match the latest conventions.)

Built by (A-Z)

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

License

This demo is MIT licensed.

More Repositories

1

react.dev

The React documentation website
TypeScript
11,041
star
2

react-transition-group

An easy way to perform animations when a React component enters or leaves the DOM
JavaScript
10,160
star
3

react-router-redux

Ruthlessly simple bindings to keep react-router and redux in sync
JavaScript
7,808
star
4

react-modal

Accessible modal dialog component for React
JavaScript
7,350
star
5

react-rails

Integrate React.js with Rails views and controllers, the asset pipeline, or webpacker.
JavaScript
6,746
star
6

react-router-tutorial

JavaScript
5,523
star
7

rfcs

RFCs for changes to React
5,502
star
8

react-basic

A description of the conceptual model of React without implementation burden.
4,181
star
9

react-codemod

React codemod scripts
JavaScript
4,164
star
10

react-docgen

A CLI and library to extract information from React component files for documentation generation purposes.
TypeScript
3,646
star
11

react-tutorial

Code from the React tutorial.
JavaScript
3,290
star
12

react-tabs

An accessible and easy tab component for ReactJS.
JavaScript
3,089
star
13

react-chartjs

common react charting components using chart.js
JavaScript
2,928
star
14

react-future

Specs & docs for potential future and experimental React APIs and JavaScript syntax.
JavaScript
2,819
star
15

express-react-views

This is an Express view engine which renders React components on server. It renders static markup and *does not* support mounting those views on the client.
JavaScript
2,734
star
16

react-a11y

Identifies accessibility issues in your React.js elements
JavaScript
2,343
star
17

React.NET

.NET library for JSX compilation and server-side rendering of React components
C#
2,293
star
18

react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component
JavaScript
2,165
star
19

react-art

React Bridge to the ART Drawing Library
JavaScript
1,994
star
20

react-php-v8js

PHP library that renders React components on the server
PHP
1,326
star
21

react-magic

Automatically AJAXify plain HTML with the power of React. It's magic!
JavaScript
947
star
22

zh-hans.react.dev

React documentation website in Simplified Chinese
TypeScript
909
star
23

core-notes

Weekly meeting notes from the React core team
900
star
24

ko.react.dev

React documentation website in Korean
TypeScript
715
star
25

ru.react.dev

React documentation website in Russian / Официальная русская версия сайта React
TypeScript
699
star
26

pt-br.react.dev

🇧🇷 React documentation website in Portuguese (Brazil)
TypeScript
484
star
27

react-lifecycles-compat

Backwards compatibility polyfill for React class components
JavaScript
459
star
28

react-gradual-upgrade-demo

Demonstration of how to gradually upgrade an app to a new version of React
JavaScript
421
star
29

id.react.dev

(Work in progress) React documentation website in Indonesian
TypeScript
312
star
30

react-timer-mixin

TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts
JavaScript
308
star
31

es.react.dev

React documentation website in Spanish / Documentación del sitio web de React en Español
TypeScript
283
star
32

translations.react.dev

Nexus of resources and tools for translating the React docs.
JavaScript
260
star
33

ja.react.dev

React documentation website in Japanese
TypeScript
258
star
34

react-static-container

Renders static content efficiently by allowing React to short-circuit the reconciliation process.
JavaScript
223
star
35

fa.react.dev

(Work in progress) React documentation website in Persian
TypeScript
190
star
36

tr.react.dev

React documentation website in Turkish
TypeScript
165
star
37

ar.react.dev

React documentation website in Arabic 📘⚛️ — وثائق React باللغة العربية
TypeScript
138
star
38

uk.react.dev

🇺🇦 React documentation website in Ukrainian / Офіційна українська версія сайту React
TypeScript
134
star
39

hi.react.dev

(Work in progress) React documentation website in Hindi
TypeScript
115
star
40

zh-hant.react.dev

(Work in progress) React documentation website in Traditional Chinese
TypeScript
106
star
41

bn.react.dev

(Work in progress) React documentation website in Bengali
TypeScript
102
star
42

fr.react.dev

Version française du site de documentation officiel de React
TypeScript
98
star
43

vi.react.dev

(Work in progress) React documentation website in Vietnamese
TypeScript
89
star
44

react-bower

[DISCONTINUED] Bower package for React
JavaScript
69
star
45

legacy.reactjs.org

An archived copy of the legacy React documentation website
JavaScript
62
star
46

bn.reactjs.org

(Work in progress) React documentation website in Bengali
JavaScript
54
star
47

ta.reactjs.org

(Work in progress) React documentation website in Tamil
JavaScript
52
star
48

pl.react.dev

React documentation website in Polish
TypeScript
49
star
49

az.react.dev

🇦🇿 React documentation website in Azerbaijani
TypeScript
43
star
50

rackt-codemod

Codemod scripts for Rackt libraries
JavaScript
40
star
51

th.reactjs.org

(Work in progress) React documentation website in Thai
JavaScript
40
star
52

mn.react.dev

(Work in progress) React documentation website in Mongolian
TypeScript
38
star
53

uz.reactjs.org

(Work in progress) React documentation website in Uzbek
TypeScript
36
star
54

de.react.dev

(Work in progress) React documentation website in German
TypeScript
35
star
55

ml.react.dev

(Work in progress) React documentation website in Malayalam
TypeScript
32
star
56

si.reactjs.org

(Work in progress) React documentation website in Sinhala
JavaScript
32
star
57

it.react.dev

(Work in progress) React documentation website in Italian
TypeScript
32
star
58

be.react.dev

(Work in progress) React documentation website in Belarusian
TypeScript
30
star
59

ur.reactjs.org

(⚠️ Beta Docs Translation only) React documentation website in Urdu. Check details in https://github.com/reactjs/ur.reactjs.org/issues/1#issuecomment-949791355
TypeScript
29
star
60

he.react.dev

(Work in progress) React documentation website in Hebrew
TypeScript
28
star
61

ku.reactjs.org

(Work in progress) React documentation website in Kurdish
JavaScript
28
star
62

ml.reactjs.org

(Work in progress) React documentation website in Malayalam
JavaScript
25
star
63

ur.react.dev

(Work in progress) React documentation website in Urdu
TypeScript
25
star
64

el.reactjs.org

(Work in progress) React documentation website in Greek
JavaScript
25
star
65

hu.react.dev

Hungarian 🇭🇺 React ⚛ documentation 📚 / React magyar dokumentációja
TypeScript
25
star
66

gu.react.dev

(Work in progress) React documentation website in Gujarati
TypeScript
24
star
67

pt-PT.reactjs.org

(Work in progress) React documentation website in Portuguese (Portugal) 🇵🇹
JavaScript
23
star
68

ne.reactjs.org

(Work in progress) React documentation website in Nepali
JavaScript
23
star
69

gu.reactjs.org

(Work in progress) React documentation website in Gujarati
JavaScript
22
star
70

te.reactjs.org

(Work in progress) React documentation website in Telugu
JavaScript
22
star
71

hy.reactjs.org

(Work in progress) React documentation website in Armenian - https://hy.reactjs.org
JavaScript
21
star
72

km.reactjs.org

(Work in progress) React documentation website in Central Khmer
JavaScript
20
star
73

bg.reactjs.org

(Work in progress) React documentation website in Bulgarian
JavaScript
16
star
74

ro.reactjs.org

(Work in progress) React documentation website in Romanian
JavaScript
16
star
75

si.react.dev

(Work in progress) React documentation website in Sinhala
TypeScript
14
star
76

kn.reactjs.org

(Work in progress) React documentation website in Kannada
JavaScript
13
star
77

tl.reactjs.org

(Work in progress) React documentation website in Tagalog
TypeScript
13
star
78

ka.reactjs.org

(Work in progress) React documentation website in Georgian
JavaScript
11
star
79

sv.reactjs.org

(Work in progress) React documentation website in Swedish
JavaScript
9
star
80

te.react.dev

(Work in progress) React documentation website in Telugu
TypeScript
9
star
81

sw.react.dev

(Work in progress) React documentation website in Swahili
TypeScript
9
star
82

nl.reactjs.org

(Work in progress) React documentation website in Dutch
JavaScript
8
star
83

ta.react.dev

(Work in progress) React documentation website in Tamil
TypeScript
8
star
84

ca.reactjs.org

(Work in progress) React documentation website in Catalan
JavaScript
7
star
85

lt.reactjs.org

(Work in progress) React documentation website in Lithuanian
JavaScript
6
star
86

ht.reactjs.org

(Work in progress) React documentation website in Haitian Creole
JavaScript
5
star
87

sr.reactjs.org

(Work in progress) React documentation website in Serbian
TypeScript
5
star
88

is.react.dev

(Work in progress) React documentation website in Icelandic
TypeScript
4
star
89

kk.react.dev

🇰🇿 React documentation website in Kazakh / React сайтының ресми қазақша нұсқасы
TypeScript
4
star
90

cs.react.dev

(Work in progress) React documentation website in Czech
TypeScript
4
star
91

sq.reactjs.org

(Work in progress) React documentation website in Albanian
TypeScript
3
star
92

sr.react.dev

(Work in progress) React documentation website in Serbian
TypeScript
3
star
93

reactjs.github.io

HTML
2
star
94

my.reactjs.org

(Work in progress) React documentation website in Burmese
JavaScript
2
star
95

lo.react.dev

(Work in progress) React documentation website in Lao
TypeScript
2
star
96

fi.react.dev

(Work in progress) React documentation website in Finnish
TypeScript
2
star
97

sw.reactjs.org

(Work in progress) React documentation website in Swahili
JavaScript
2
star
98

mk.react.dev

(Work in progress) React documentation website in Macedonian
TypeScript
1
star
99

tg.reactjs.org

(Work in progress) React documentation website in Tajik
TypeScript
1
star