• Stars
    star
    277
  • Rank 148,875 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

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

Repository Details

⚛️ Boilerplate for isomorphic web app with React server-side rendering in TypeScript

react-server-example-tsx

npm Downloads Dependency Status devDependency Status LGTM Quality Build Status

A complex example of how to do server-side rendering with React and TypeScript so that component code can be shared between server and browser (also known as isomorphic javascript).

Server-Side Rendering (SSR) leads to fast initial page loads, search-engine-friendly pages, and of course...its all type safe!

Getting Started

Clone the repo, change directory, install dependencies, build the code, and run it!

git clone https://github.com/styfle/react-server-example-tsx.git
cd react-server-example-tsx
npm install
npm run vercel-build
npm run test
npm start

Then navigate to http://localhost:3007 and click on the buttons to see some reactive events in action.

Preventing XSS

The original code from mhart attempts to sanitize the props by escaping and then inserting into a <script> tag.

I avoided this by performing 1 extra http request to fetch the props as json before initializing React in the browser. This means that click handlers will not be initialized until the data is returned and React can pick up where it left off after the server-side render and attach the click even handlers. This is the purpose of ReactDOM.hydrate.

See browser.tsx for the client-side code.

See server.ts for the server-side code.

Prior art

Based on prior work found at mhart/react-server-example. It's very good so you should check it out :)

Additionally, I use a combination between TypeScript Handbook and awesome-typescript-loader when I switched from browserify v1.4.x to webpack v2.0.x (now webpack v4.x).

Author

Developed by styfle, the author of Package Phobia

More Repositories

1

awesome-online-ide

🌩️ A list of awesome online development environments
2,919
star
2

packagephobia

⚖️ Find the cost of adding a new dependency to your project
TypeScript
2,115
star
3

cancel-workflow-action

⏹️ GitHub Action to cancel previous running workflows on push
TypeScript
863
star
4

awesome-desktop-js

🖥️ A list of awesome packages and frameworks for implementing javascript applications on the desktop
740
star
5

breaking-changes-web

💢 A list of breaking changes to the web platform
351
star
6

copee

📄 Copy text from browser to clipboard...natively! < 1kB
TypeScript
138
star
7

links-awakening

🔗 Recursively check a website for broken links
TypeScript
130
star
8

magnemite

⏺️ Capture repro steps with this screen recorder for websites, powered by Electron
TypeScript
57
star
9

screenshot-v2

New here and want something similar? See https://github.com/vercel/og-image. Historian and want to see the original PR? See https://github.com/zeit/now-examples/pull/207
JavaScript
30
star
10

styfle.dev

👨‍💻 The source code for my website, built with Next.js and hosted on Vercel
TypeScript
23
star
11

geoslack

📍 Geolocate your team in Slack
TypeScript
18
star
12

doorbell

🛎️ Virtual doorbell to notify Amazon Alexa devices
HTML
15
star
13

tls-check

✅ Check the TLS protocol support of one or more web servers
JavaScript
13
star
14

typed-tmpl

🛡A typed, template module using ES6 Tagged Template Strings with TypeScript
JavaScript
6
star
15

The-Harvest-Club

🍊A student-designed Contact Management System for connecting volunteers and growers
PHP
6
star
16

exeggcute

🥚 A node.js module to make executing shell cmds a breeze!
JavaScript
5
star
17

rediscovering-neverland

🧚‍♂️Slides from my Tech Talk given on January 23, 2020
HTML
5
star
18

Basic-Wars

🎖️A turn-based strategy game written in pure Java
Java
4
star
19

dotfiles

⚫ My .bashrc .vimrc etc
Vim Script
3
star
20

tsc-example

Different ways to compile typescript
JavaScript
3
star
21

ncc-bug-socketio

A bug with ncc
JavaScript
2
star
22

ncc-bug-stack

JavaScript
2
star
23

device-width-detection

📱Generate dynamic SVG based on device srcset
JavaScript
2
star
24

ncc-bug-sourcemap

A bug with ncc
TypeScript
2
star
25

dotnet-api-example

Example of what a simple .NET API might look like
C#
1
star
26

ncc-bug-fluent-ffmpeg

JavaScript
1
star
27

micro-ts-example

Example of using micro with TypeScript
JavaScript
1
star
28

ncc-bug-npm

A bug when npm is a dependency
JavaScript
1
star
29

alexa-wunderground

🗣️ WIP - An Amazon Alexa skill for Weather Underground
JavaScript
1
star
30

xtend-es6

extend like a modern boss with Object.assign()
JavaScript
1
star
31

aws-xray-bug

aws xray issue #60
JavaScript
1
star
32

mma-api

👊 api for mma dataset
JavaScript
1
star
33

node-docker-echo

Example node.js echo environment variables in docker
JavaScript
1
star
34

node-http-log

❓ log http request header & body to a file
JavaScript
1
star
35

bug-term-size-tput

Bug in `term-size`
JavaScript
1
star