8000 GitHub - alex996/react-exercises at ssr/starter
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 5, 2021. It is now read-only.

alex996/react-exercises

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Material-UI - Server-side Rendering (SSR)

Note: use this branch along with its companion video to migrate from SPA to SSR. For the latest code, see master branch.

Render the React app on the server, and boot it up on the client.

Why

  • faster first meaningful paint
    • initial render much quicker (ex: 10s vs. 3s on slow 3G)
  • better SEO (search engine optimization)

How

  • client sends a GET request to the server
  • server renders the component tree into an HTML string
  • it extracts critical CSS and injects it inline
  • it sends off HTML & CSS as a response to the client
  • client paints the page with HTML & CSS and loads JS async (viewable)
  • once JS is loaded, React
    • hydrates server-rendered markup, and
    • attaches event listeners to existing markup (interactive)

Build Setup

  • have to transpile JSX server-side preset-react
  • might as well use import (ESM) and transpile to require (CJS)
  • for dev, could use @babel/node to compile on the fly in memory
  • for prod, could use @babel/cli to precompile our code for execution
  • might as well bundle with webpack since it's already part of build setup

Integration

Server
  • JssProvider
    • sheets registry: SheetsRegistry
    • class name generator: createGenerateClassName
  • MuiThemeProvider
    • theme instance: createMuiTheme
    • sheets manager: Map
Client
  • JssProvider
    • class name generator: createGenerateClassName
  • MuiThemeProvider
    • theme instance: createMuiTheme

Caveats

Integration is a very intricate procedure! You must make sure to

  • provide a new sheets manager on each request
  • provide a new class name generator on each request
  • use JssProvider with a class name generator on the client
  • use the same version of material-ui on the client & server

About

Exercise DB with React & Material-UI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0