Skip to content

Commit 5e88714

Browse files
feat(react-router-dom): support future options (#45)
1 parent 053c8d6 commit 5e88714

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/client/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ export function ViteReactSSG(
2828
const isClient = typeof window !== 'undefined'
2929

3030
const BASE_URL = routerOptions.basename ?? '/'
31+
const { v7_startTransition, ...routerFeature } = routerOptions.future ?? {}
3132

3233
async function createRoot(client = false, routePath?: string) {
33-
const browserRouter = client ? createBrowserRouter(convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute), { basename: BASE_URL }) : undefined
34+
const browserRouter = client
35+
? createBrowserRouter(
36+
convertRoutesToDataRoutes(routerOptions.routes, transformStaticLoaderRoute),
37+
{ basename: BASE_URL, future: routerFeature },
38+
)
39+
: undefined
3440

3541
const appRenderCallbacks: Function[] = []
3642
const onSSRAppRendered = client
@@ -106,7 +112,7 @@ export function ViteReactSSG(
106112
const { router } = await createRoot(true)
107113
const app = (
108114
<HelmetProvider>
109-
<RouterProvider router={router!} />
115+
<RouterProvider router={router!} future={{ v7_startTransition }} />
110116
</HelmetProvider>
111117
)
112118
const isSSR = document.querySelector('[data-server-rendered=true]') !== null

src/node/router-adapter/remix.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class RemixAdapter implements IRouterAdapter<ViteReactSSGContext> {
2020
}
2121

2222
async render(path: string) {
23-
const { base, routes, getStyleCollector } = this.context
23+
const { base, routes, getStyleCollector, routerOptions } = this.context
2424
const fetchUrl = `${withTrailingSlash(base)}${removeLeadingSlash(path)}`
2525
const request = createRequest(fetchUrl)
2626
const styleCollector = getStyleCollector ? await getStyleCollector() : null
@@ -34,7 +34,7 @@ export class RemixAdapter implements IRouterAdapter<ViteReactSSGContext> {
3434
throw _context
3535

3636
routerContext = _context
37-
const router = createStaticRouter(dataRoutes, routerContext)
37+
const router = createStaticRouter(dataRoutes, routerContext, { future: routerOptions.future })
3838
let app = (
3939
<HelmetProvider context={helmetContext}>
4040
<StaticRouterProvider router={router} context={routerContext} />

src/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactElement, ReactNode } from 'react'
2-
import type { IndexRouteObject, NonIndexRouteObject, createBrowserRouter } from 'react-router-dom'
2+
import type { FutureConfig as CompFutureConfig, IndexRouteObject, NonIndexRouteObject, createBrowserRouter } from 'react-router-dom'
33
import type { Options as BeastiesOptions } from 'beasties'
44

55
type Router = ReturnType<typeof createBrowserRouter>
@@ -198,10 +198,18 @@ export type IndexRouteRecord = IndexRouteObject & CommonRouteOptions
198198

199199
export type RouteRecord = NonIndexRouteRecord | IndexRouteRecord
200200

201+
export interface RouterFutureConfig {
202+
v7_fetcherPersist?: boolean
203+
v7_normalizeFormMethod?: boolean
204+
v7_partialHydration?: boolean
205+
v7_relativeSplatPath?: boolean
206+
v7_skipActionErrorRevalidation?: boolean
207+
}
208+
201209
export interface RouterOptions {
202210
routes: RouteRecord[]
203-
createFetchRequest?: <T>(req: T) => Request
204211
basename?: string
212+
future?: Partial<RouterFutureConfig & CompFutureConfig>
205213
}
206214

207215
export interface StyleCollector {

0 commit comments

Comments
 (0)