-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make NestJS examples work again
- Loading branch information
Showing
14 changed files
with
76 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
examples/fastify-vite-plugin-ssr/renderer/_default.page.client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import ReactDOM from "react-dom"; | ||
import React from "react"; | ||
import { PageWrapper } from "./PageWrapper"; | ||
import type { PageContext } from "./types"; | ||
import type { PageContextBuiltInClient } from "vite-plugin-ssr/types"; | ||
import { PageContextBuiltInClientWithClientRouting } from "vite-plugin-ssr/types"; | ||
import { hydrateRoot } from "react-dom/client"; | ||
|
||
export async function render( | ||
pageContext: PageContextBuiltInClient & PageContext, | ||
pageContext: PageContextBuiltInClientWithClientRouting & PageContext, | ||
) { | ||
const { Page, pageProps } = pageContext; | ||
ReactDOM.hydrate( | ||
hydrateRoot( | ||
document.getElementById("page-view")!, | ||
<PageWrapper pageContext={pageContext}> | ||
<Page {...pageProps} /> | ||
</PageWrapper>, | ||
document.getElementById("page-view"), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 9 additions & 21 deletions
30
examples/nestjs-vite-plugin-ssr/renderer/_default.page.client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import { Root, hydrateRoot, createRoot } from "react-dom/client"; | ||
import type { PageContextBuiltInClient } from "vite-plugin-ssr/client/router"; | ||
import type { PageContext } from "./types"; | ||
import { PageWrapper } from "./PageWrapper"; | ||
import type { PageContext } from "./types"; | ||
import { PageContextBuiltInClientWithClientRouting } from "vite-plugin-ssr/types"; | ||
import { hydrateRoot } from "react-dom/client"; | ||
|
||
export { render }; | ||
|
||
export const clientRouting = true; | ||
let root: Root | null = null; | ||
|
||
async function render(pageContext: PageContextBuiltInClient & PageContext) { | ||
export async function render( | ||
pageContext: PageContextBuiltInClientWithClientRouting & PageContext, | ||
) { | ||
const { Page, pageProps } = pageContext; | ||
const page = ( | ||
hydrateRoot( | ||
document.getElementById("page-view")!, | ||
<PageWrapper pageContext={pageContext}> | ||
<Page {...pageProps} /> | ||
</PageWrapper> | ||
</PageWrapper>, | ||
); | ||
const container = document.getElementById("page-view")!; | ||
if (container.innerHTML === "" || !pageContext.isHydration) { | ||
if (!root) { | ||
root = createRoot(container); | ||
} | ||
root.render(page); | ||
// SSR | ||
} else { | ||
root = hydrateRoot(container, page); | ||
} | ||
} |
64 changes: 29 additions & 35 deletions
64
examples/nestjs-vite-plugin-ssr/renderer/_default.page.server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,48 @@ | ||
import { renderToPipeableStream } from "react-dom/server"; | ||
// @ts-expect-error - no types | ||
import reactStreaming from "react-streaming/server"; | ||
import { escapeInject } from "vite-plugin-ssr/server"; | ||
import type { PageContextBuiltIn } from "vite-plugin-ssr"; | ||
import type { PageContext } from "./types"; | ||
|
||
import logoUrl from "./logo.svg"; | ||
import ReactDOMServer from "react-dom/server"; | ||
import { PageWrapper } from "./PageWrapper"; | ||
import { escapeInject, dangerouslySkipEscape } from "vite-plugin-ssr/server"; | ||
import logoUrl from "./logo.svg"; | ||
import type { PageContext } from "./types"; | ||
import type { PageContextBuiltIn } from "vite-plugin-ssr/types"; | ||
|
||
export { render }; | ||
|
||
// See https://vite-plugin-ssr.com/data-fetching | ||
export const passToClient = ["pageProps"]; | ||
export const passToClient = ["pageProps", "urlPathname"]; | ||
|
||
async function render(pageContext: PageContextBuiltIn & PageContext) { | ||
const { Page, pageProps } = pageContext; | ||
const pageHtml = ReactDOMServer.renderToString( | ||
<PageWrapper pageContext={pageContext}> | ||
<Page {...pageProps} /> | ||
</PageWrapper>, | ||
); | ||
|
||
// See https://vite-plugin-ssr.com/html-head | ||
const { documentProps } = pageContext; | ||
const title = (documentProps && documentProps.title) || "App"; | ||
let stream; | ||
const title = (documentProps && documentProps.title) || "Vite SSR app"; | ||
const desc = | ||
(documentProps && documentProps.description) || | ||
"App using Vite + vite-plugin-ssr"; | ||
|
||
if (pageContext.Page) { | ||
const { Page, pageProps } = pageContext; | ||
stream = await reactStreaming.renderToStream( | ||
<PageWrapper pageContext={pageContext}> | ||
<Page {...pageProps} /> | ||
</PageWrapper>, | ||
{ | ||
disable: false, | ||
webStream: false, | ||
renderToPipeableStream, | ||
}, | ||
); | ||
} else { | ||
stream = ""; | ||
} | ||
// See https://vite-plugin-ssr.com/head | ||
return { | ||
documentHtml: escapeInject`<!DOCTYPE html> | ||
const documentHtml = escapeInject`<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta name="color-scheme" content="dark light" /> | ||
<meta name="description" content="App" /> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="${logoUrl}" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="description" content="${desc}" /> | ||
<title>${title}</title> | ||
</head> | ||
<body style="height: 100vh;"> | ||
<div id="page-view" style="height: 100%; overflow: hidden;">${stream}</div> | ||
<body> | ||
<div id="page-view">${dangerouslySkipEscape(pageHtml)}</div> | ||
</body> | ||
</html>`, | ||
pageContext: {}, | ||
</html>`; | ||
|
||
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 | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import ReactDOM from "react-dom"; | ||
import React from "react"; | ||
import { PageWrapper } from "./PageWrapper"; | ||
import type { PageContext } from "./types"; | ||
import type { PageContextBuiltInClient } from "vite-plugin-ssr/types"; | ||
import { PageContextBuiltInClientWithClientRouting } from "vite-plugin-ssr/types"; | ||
import { hydrateRoot } from "react-dom/client"; | ||
|
||
export async function render( | ||
pageContext: PageContextBuiltInClient & PageContext, | ||
pageContext: PageContextBuiltInClientWithClientRouting & PageContext, | ||
) { | ||
const { Page, pageProps } = pageContext; | ||
ReactDOM.hydrate( | ||
hydrateRoot( | ||
document.getElementById("page-view")!, | ||
<PageWrapper pageContext={pageContext}> | ||
<Page {...pageProps} /> | ||
</PageWrapper>, | ||
document.getElementById("page-view"), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { Server } from "node:http"; | ||
|
||
declare const httpDevServer: Server | undefined; | ||
const httpDevServer: Server | undefined = undefined; | ||
|
||
export default httpDevServer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { Server } from "node:http"; | ||
|
||
declare const httpDevServer: Server | undefined; | ||
const httpDevServer: Server | undefined = undefined; | ||
|
||
export default httpDevServer; |
Oops, something went wrong.