score:2
when implementing server side rendering (ssr), the server knows how to generate a full page with markup so the user gets a fully rendered page and from that moment, when the js resources get downloaded, the application will be live (event listeners will be enabled, the react lifecycle will be active and so on).
suppose you have app component that is an entry point for you app, a general ssr implementation will:
- get a request for a specific path
- initiate a new store instance for the request
- in case of using react router (or other router solution), fill the state with the requested route
- render the app, but instead of rendering and mounting the app, render the app to string (with rendertostring)
- dehydrate the state - take the latest state snapshot and append it to the result (after escaping it and wrapping it with script tag for example)
- return the markup as a response. the markup can look similar to the following:
<html>
...
...
<body>
...
<app markup>
...
<script><window.state = {state snapshot}></script>
</body>
</html>
- the browser gets the html and renders it (before react), so the user already have something on the screen
- the browser downloads the app bundle
- the app bundle includes the app that initiate the state with the provided state snapshot (rehydrate)
- the app rendered into the dom, if done correctly, no actual dom rendering should happen since the result will be the same (app rendered according the same state as it was rendered in the server)
- from this point the app behaves regular. any route change doesn't trigger the ssr engine
there are several frameworks (next.js for example) that comes out of the box with ssr solution along with code splitting according to routes. so when the user change route, a new backend request triggers the ssr flow again for the new route.
ssr can be implemented in many different variations, but the basic stays the smame
hope this gives a good starting point for understanding ssr.
Source: stackoverflow.com
Related Query
- How can I make my Single Page Application (SPA) based on React render conditionally?
- How can i create a login page separately from my other single page application in react js
- How to add Canonical Tag to single page application in react js?
- How to force update Single Page Application (SPA) pages?
- How to format time in React SSR rendered page using client time zone?
- How to implement the OAuth2 Authorization code grant with PKCE for a React single page application?
- How to code split in a single page application in react?
- How to deploy a React SSR application to Heroku?
- how to update a route in React Router without re-mounting the component in a single page app?
- Why is React Js called as Single Page Application
- How to create a Single Page Application using react-router
- How authorization code flow works in single page applications?
- How do you clean up an embedded youtube subscribe button on a single page application
- Redirect to welcome page on pressing back button in react Single page application
- How to scroll to the particular div on button click in a single page application using react-router?
- How can I include a compiled react js component from a compiled react js single page app?
- How do I search text in a single page reactjs/electron application
- Redux, React for single page application login and logout
- How to use dynamic meta tags in react single page application?
- How can I show single data per page in react with javascript data file?
- Force re-render the react component in the jquery single page application or in static html site?
- How to do nested routing for multiple components in single page in react
- How to serve a React/Javascript single page application
- How to use React Router properly? I am trying to push the state of my application to another page when the user logs in
- How single-page application works in SSR (React)
- How to write JS which working on single page of react router at project created create-react-app
- How to handle multiple select dropdowns in a React application with a single function?
- React single page application
- How to set starting page or controller method of a web application when we are deploying the React or Angular or Ember applications
- How to Host two react js application on single application pool?
More Query from same tag
- Google Cloud: Storage and App Engine
- How can I render a <template /> tag with react?
- Got troubles to deploy on Heroku
- how to pass input data to another component in react
- Components that do not consume from context still re-render
- Modify Json to use into React beautiful Drag and drop
- Showing all the results of news api in react
- Handling authentication in Relay Modern
- React: How to render a list of items grouped by category (using .map)
- Array does not update with useState hook and for loop
- How to deploy separated frontend and backend?
- How to add spacing between rows in material UI/React?
- Why is function on onClick on <li> tag runs before even clicked?
- Select more than one radio button that are mapped into different radio groups - React
- Override margin in Separator Component of Fluent UI using React
- How to reset child elements' state?
- react select styles and typescript
- how to make page re-render after localstorage change
- react-bootstrap-table-next on selectRow selects all Rows
- Webpack how to build production code and how to use it
- Creating second level nav with ReactRouter
- How to pass the dynamic state and setState to function typescript
- How to pass props to children according to type in React + Typescript
- How can I assign a key to an item in my array in react js?
- how to fix an element in bottom while the keyboard is open
- access to navigate methods React-Big-Calendar and Typescript
- Action not being called - flux react
- How to store to an array
- How to overwrite default props of a higher order component?
- Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response