Skip to content

Commit

Permalink
feat: ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Dec 12, 2024
1 parent fa119bd commit 7a99b55
Show file tree
Hide file tree
Showing 8 changed files with 1,240 additions and 738 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Redux App</title>
<!--app-head-->
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<div id="root"><!--app-html--></div>
<script type="module" src="/src/entry-client.tsx"></script>
</body>
</html>
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"start": "serve -s dist",
"build": "tsc --build tsconfig.json && vite build",
"preview": "vite preview",
"dev:server": "node server",
"dev:client": "vite",
"start": "NODE_ENV=production node server",
"build": "npm run build:client && npm run build:server",
"build:client": "vite build --outDir dist/client",
"build:server": "vite build --ssr src/entry-server.tsx --outDir dist/server",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:verbose": "vitest run --reporter=verbose --coverage.thresholds.lines=90 --coverage.thresholds.functions=90 --coverage.thresholds.branches=90 --coverage.thresholds.statements=90",
Expand All @@ -26,14 +28,15 @@
"type-check": "tsc --build tsconfig.json"
},
"dependencies": {
"codeforlife": "github:ocadotechnology/codeforlife-package-javascript#v2.5.0"
"codeforlife": "github:ocadotechnology/codeforlife-package-javascript#otp_deploy"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.12",
"@types/js-cookie": "^3.0.3",
"@types/node": "^20.14.2",
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Server from "codeforlife/src/server.js"

new Server().run()
14 changes: 10 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { App as _App, type AppProps as _AppProps } from "codeforlife/components"
import { type FC } from "react"
import { App as _ } from "codeforlife/components"

import { Header } from "./components"
import routes from "./routes"
import store from "./app/store"
import theme from "./app/theme"

export interface AppProps {}
export interface AppProps extends Pick<_AppProps, "path"> {}

const App: FC<AppProps> = () => (
<_ store={store} theme={theme} routes={routes} header={<Header />} />
const App: FC<AppProps> = props => (
<_App
store={store}
theme={theme}
routes={routes}
header={<Header />}
{...props}
/>
)

export default App
11 changes: 11 additions & 0 deletions src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { StrictMode } from "react"
import { hydrateRoot } from "react-dom/client"

import App from "./App"

hydrateRoot(
document.getElementById("root") as HTMLElement,
<StrictMode>
<App />
</StrictMode>,
)
14 changes: 14 additions & 0 deletions src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { StrictMode } from "react"
import { renderToString } from "react-dom/server"

import App from "./App"

export function render(path: string) {
return {
html: renderToString(
<StrictMode>
<App path={path} />
</StrictMode>,
),
}
}
20 changes: 0 additions & 20 deletions src/main.tsx

This file was deleted.

1,897 changes: 1,191 additions & 706 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 7a99b55

Please sign in to comment.