Skip to content

Commit

Permalink
Fix mismatch hydration on spa
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Apr 20, 2023
1 parent 7324a95 commit 7da9b8c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!--app-state-->
</head>
<body>
<div id="app"><!--app-html--></div>
<div id="app"></div>
<script
type="module"
src="/src/entry-client.js"
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "node server",
"dev:spa": "vite dev",
"build:spa": "vite build",
"build": "npm run build:client && npm run build:server",
"dev:ssr": "node server",
"dev": "vite dev",
"build": "vite build",
"build:ssr": "npm run build:client && npm run build:server",
"build:client": "vite build --ssrManifest --outDir dist/client",
"build:server": "vite build --ssr src/entry-server.js --outDir dist/server",
"serve": "NODE_ENV=production node server",
Expand Down
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export async function createServer(

const html = template
.replace(`<!--preload-links-->`, preloadLinks)
.replace(`<!--app-html-->`, appHtml)
.replace(`<!--app-state-->`, appState)
.replace(makeAppContainer(), makeAppContainer(appHtml))

res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
} catch (e) {
Expand All @@ -105,4 +105,8 @@ if (!isTest) {
generateConsoleMessage({ port: 6173, url: 'http://localhost' })
})
)
}

function makeAppContainer(app = '') {
return `<div id="app">${app}</div>`
}
2 changes: 1 addition & 1 deletion src/ssr/utils/generateConsoleMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export function generateConsoleMessage ({ url, port }) {

console.log(taxonPagesMark)
console.log('----------------------------------------------------------')
console.log('Server running at: ', `${url}:${port}`)
console.log('Server running at:', `${url}:${port}`)

}

0 comments on commit 7da9b8c

Please sign in to comment.