Skip to content

Commit 9552448

Browse files
refactor!: replace createApp with createRoot
1 parent 8ab816a commit 9552448

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Static-site generation for React on Vite.
3131
import { ViteReactSSG } from 'vite-react-ssg'
3232
import routes from './App.tsx'
3333

34-
export const createApp = ViteReactSSG(
34+
export const createRoot = ViteReactSSG(
3535
// react-router-dom data routes
3636
{ routes },
3737
// function to have custom setups

examples/multiple-pages/src/main.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ import { ViteReactSSG } from 'vite-react-ssg'
22
import { routes } from './App.js'
33
import './index.css'
44

5-
export const createApp = ViteReactSSG({ routes })
6-
7-
// export const createApp = ViteReactSSG(
8-
// <App />,
9-
// routes,
10-
// )
5+
export const createRoot = ViteReactSSG({ routes })

src/client/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function ViteReactSSG(
2020

2121
const isClient = typeof window !== 'undefined'
2222

23-
async function createApp(client = false, routePath?: string) {
23+
async function createRoot(client = false, routePath?: string) {
2424
const browserRouter = client ? createBrowserRouter(routerOptions.routes) : undefined
2525

2626
const appRenderCallbacks: Function[] = []
@@ -69,7 +69,7 @@ export function ViteReactSSG(
6969
const container = typeof rootContainer === 'string'
7070
? document.querySelector(rootContainer)!
7171
: rootContainer
72-
const { router } = await createApp(true)
72+
const { router } = await createRoot(true)
7373
hydrateRoot(container, (
7474
<HelmetProvider>
7575
<SiteMetadataDefaults />
@@ -79,7 +79,7 @@ export function ViteReactSSG(
7979
})()
8080
}
8181

82-
return createApp
82+
return createRoot
8383
}
8484

8585
export { default as Head } from './components/Head'

src/node/build.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { renderPreloadLinks } from './preload-links'
1717

1818
export type Manifest = Record<string, string[]>
1919

20-
export type CreateAppFactory = (client: boolean, routePath?: string) => Promise<ViteReactSSGContext<true> | ViteReactSSGContext<false>>
20+
export type CreateRootFactory = (client: boolean, routePath?: string) => Promise<ViteReactSSGContext<true> | ViteReactSSGContext<false>>
2121

2222
function DefaultIncludedRoutes(paths: string[], _routes: Readonly<RouteRecord[]>) {
2323
// ignore dynamic routes
@@ -104,11 +104,11 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
104104

105105
const _require = createRequire(import.meta.url)
106106

107-
const { createApp, includedRoutes: serverEntryIncludedRoutes }: { createApp: CreateAppFactory; includedRoutes: ViteReactSSGOptions['includedRoutes'] } = format === 'esm'
107+
const { createRoot, includedRoutes: serverEntryIncludedRoutes }: { createRoot: CreateRootFactory; includedRoutes: ViteReactSSGOptions['includedRoutes'] } = format === 'esm'
108108
? await import(serverEntry)
109109
: _require(serverEntry)
110110
const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes
111-
const { routes } = await createApp(false)
111+
const { routes } = await createRoot(false)
112112

113113
let routesPaths = includeAllRoutes
114114
? routesToPaths(routes)
@@ -132,7 +132,7 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
132132
console.log('🚀 ~ file: build.ts:132 ~ build ~ routesPaths:', routesPaths)
133133
queue.add(async () => {
134134
try {
135-
const appCtx = await createApp(false, route) as ViteReactSSGContext<true>
135+
const appCtx = await createRoot(false, route) as ViteReactSSGContext<true>
136136
const { app: innerApp, routes, initialState, triggerOnSSRAppRendered, transformState = serializeState } = appCtx
137137

138138
const transformedIndexHTML = (await onBeforePageRender?.(route, indexHTML, appCtx))

0 commit comments

Comments
 (0)