This is a modified version of the original demo that works with Vite -- HIGHLY EXPERIMENTAL The original source of react-server-dom-vite package is based on @shopify/hydrogen and is located here.
- What is this?
- When will I be able to use this?
- Setup
- DB Setup
- Notes about this app
- Built by (A-Z)
- Code of Conduct
- License
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.
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.
You will need to have nodejs >=14.9.0 in order to run this demo. Node 14 LTS is a good choice! (If you use nvm
, run nvm i
before running npm install
to install the recommended Node version.)
npm install
npm start
(Or npm run start:prod
for a production build.)
Then open http://localhost:3000.
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.
If you prefer Docker, make sure you have docker and docker-compose installed then run:
docker-compose up
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.
This demo uses SQLite3. Nothing to setup.
The demo is a note-taking app called React Notes. It consists of a few major parts:
- It uses a Vite plugin (not defined in this repo) that allows us to only include client components in build artifacts
- A Node.js 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
- 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
fetch('http://127.0.0.1:3000/sleep/....')
call inNote.server.js
orNoteList.server.js
to introduce an artificial delay and trigger Suspense.- If you only uncomment it in
Note.server.js
, you'll see the fallback every time you open a note. - If you only uncomment it in
NoteList.server.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.
- If you only uncomment it in
- Add a new Server Component and place it above the search bar in
App.server.js
. Importdb
fromdb.server
and usedb.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).
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.
This demo is MIT licensed.