Skip to content

Commit

Permalink
Merge pull request #10 from Hillsie/chore/vite-plugin-ssr-to-vike
Browse files Browse the repository at this point in the history
Chore/vite plugin ssr to vike
  • Loading branch information
rschristian authored Oct 11, 2023
2 parents 90a84a1 + 76b5d49 commit f52d1ae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion templates/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"devDependencies": {
"@preact/preset-vite": "^2.5.0",
"vite": "^4.3.2",
"vite-plugin-ssr": "^0.4.133"
"vike": "^0.4.143"
}
}
4 changes: 2 additions & 2 deletions templates/ssr/renderer/_default.page.client.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { render };
import { hydrate } from 'preact';
import { PageShell } from './PageShell';

// This render() hook only supports SSR, see https://vite-plugin-ssr.com/render-modes for how to modify render() to support SPA
// This render() hook only supports SSR, see https://vike.dev/render-modes for how to modify render() to support SPA
async function render(pageContext) {
const { Page, pageProps } = pageContext;
if (!Page) throw new Error('Client-side render() hook expects pageContext.Page to be defined');
Expand All @@ -20,4 +20,4 @@ async function render(pageContext) {

/* To enable Client-side Routing:
export const clientRouting = true
// !! WARNING !! Before doing so, read https://vite-plugin-ssr.com/clientRouting */
// !! WARNING !! Before doing so, read https://vike.dev/clientRouting */
12 changes: 6 additions & 6 deletions templates/ssr/renderer/_default.page.server.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
export { render };
// See https://vite-plugin-ssr.com/data-fetching
// See https://vike.dev/data-fetching
export const passToClient = ['pageProps', 'urlPathname'];

import { renderToString } from 'preact-render-to-string';
import { PageShell } from './PageShell';
import { escapeInject, dangerouslySkipEscape } from 'vite-plugin-ssr/server';
import { escapeInject, dangerouslySkipEscape } from 'vike/server';

async function render(pageContext) {
const { Page, pageProps } = pageContext;
// This render() hook only supports SSR, see https://vite-plugin-ssr.com/render-modes for how to modify render() to support SPA
// This render() hook only supports SSR, see https://vike.dev/render-modes for how to modify render() to support SPA
if (!Page) throw new Error('My render() hook expects pageContext.Page to be defined');
const pageHtml = renderToString(
<PageShell pageContext={pageContext}>
<Page {...pageProps} />
</PageShell>,
);

// See https://vite-plugin-ssr.com/head
// See https://vike.dev/head
const { documentProps } = pageContext.exports;
const title = (documentProps && documentProps.title) || 'Vite SSR + Preact';
const desc =
(documentProps && documentProps.description) || 'Preact app with Vite and vite-plugin-ssr';
(documentProps && documentProps.description) || 'Preact app with Vite and vike';

const documentHtml = escapeInject`<!DOCTYPE html>
<html lang="en">
Expand All @@ -40,7 +40,7 @@ async function render(pageContext) {
return {
documentHtml,
pageContext: {
// We can add some `pageContext` here, which is useful if we want to do page redirection https://vite-plugin-ssr.com/page-redirection
// We can add some `pageContext` here, which is useful if we want to do page redirection https://vike.dev/page-redirection
},
};
}
2 changes: 1 addition & 1 deletion templates/ssr/renderer/usePageContext.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// `usePageContext` allows us to access `pageContext` in any Preact component.
// See https://vite-plugin-ssr.com/pageContext-anywhere
// See https://vike.dev/pageContext-anywhere

import { createContext } from 'preact';
import { useContext } from 'preact/hooks';
Expand Down
2 changes: 1 addition & 1 deletion templates/ssr/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import ssr from 'vite-plugin-ssr/plugin';
import ssr from 'vike/plugin';

// https://vitejs.dev/config/
export default defineConfig({
Expand Down

0 comments on commit f52d1ae

Please sign in to comment.