Skip to content

Commit

Permalink
more ssr work
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Jul 28, 2023
1 parent 07e8d89 commit 225dd56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/tonic-components/package.json
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@siteup/cli": "../../.",
"@socketsupply/tonic": "^15.1.1",
"jsdom": "^22.1.0",
"mine.css": "^9.0.1",
"tonic-ssr": "github:socketsupply/tonic-ssr#f447a8ae2bec27a526ae489fa8510a1c646f4a66"
},
Expand Down
4 changes: 3 additions & 1 deletion examples/tonic-components/src/root.layout.js
Expand Up @@ -6,7 +6,8 @@ export default async function RootLayout ({
siteName,
scripts,
styles,
children
children,
head
}) {
return /* html */`
<!DOCTYPE html>
Expand All @@ -21,6 +22,7 @@ export default async function RootLayout ({
${styles
? styles.map(style => /* html */`<link rel="stylesheet" href=${style} />`).join('\n')
: ''}
${head || ''}
</head>
<body>
<parent-component>
Expand Down
22 changes: 18 additions & 4 deletions examples/tonic-components/src/ssr-page/page.js
@@ -1,8 +1,22 @@
import 'tonic-ssr'
import { MainComponent } from './client.js'
import jsdom from 'jsdom'

export default () => {
return (new MainComponent({
timestamp: 1611695921286
})).preRender()
const { JSDOM } = jsdom

const page = await (new MainComponent({
timestamp: 1611695921286
})).preRender()

console.log({ page })

const dom = new JSDOM(`<!DOCTYPE html>${page}`)

const body = dom.window.document.querySelector('body')
const head = dom.window.document.querySelector('head')

export default () => `<main-component>${body.innerHTML}</main-component>`

export const vars = {
head: head.innerHTML
}

0 comments on commit 225dd56

Please sign in to comment.