@lomray/vite-ssr-boost 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,10 +15,11 @@ type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;
15
15
  interface IEntryClientOptions<T> {
16
16
  init?: (params: IInitPropsParams) => Promise<T>;
17
17
  routerOptions?: Parameters<typeof createBrowserRouter>[1];
18
+ createRouter?: typeof createBrowserRouter;
18
19
  rootId?: string;
19
20
  }
20
21
  /**
21
22
  * Render client side application
22
23
  */
23
- declare function entry<TAppProps>(App: TApp<TAppProps>, routes: TRouteObject[], { init, routerOptions, rootId }?: IEntryClientOptions<TAppProps>): Promise<ReactDOM.Root | void>;
24
+ declare function entry<TAppProps>(App: TApp<TAppProps>, routes: TRouteObject[], { init, routerOptions, createRouter, rootId, }?: IEntryClientOptions<TAppProps>): Promise<ReactDOM.Root | void>;
24
25
  export { entry as default, IAppClientProps, IInitPropsParams, TApp, IEntryClientOptions };
package/browser/entry.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"react";import e from"react-dom/client";import{matchRoutes as o,createBrowserRouter as r,RouterProvider as a}from"react-router-dom";import{IS_SSR_MODE as n}from"../constants/common.js";async function c(c,i,{init:l,routerOptions:m,rootId:s="root"}={}){const u=o(i,window.location)?.filter((t=>t.route.lazy));u&&u?.length>0&&await Promise.all(u.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const d=r(i,m),f=document.getElementById(s),p=await(l?.({isSSRMode:n,router:d})),y=()=>t.createElement(c,{client:p},t.createElement(a,{router:d}));return n&&"1"!==f.dataset.forceSpa?e.hydrateRoot(f,t.createElement(y,null)):e.createRoot(f).render(t.createElement(y,null))}export{c as default};
1
+ import t from"react";import e from"react-dom/client";import{matchRoutes as o,createBrowserRouter as r,RouterProvider as a}from"react-router-dom";import{IS_SSR_MODE as n}from"../constants/common.js";async function c(c,i,{init:l,routerOptions:m,createRouter:s=r,rootId:u="root"}={}){const d=o(i,window.location)?.filter((t=>t.route.lazy));d&&d?.length>0&&await Promise.all(d.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const f=s(i,m),p=document.getElementById(u),y=await(l?.({isSSRMode:n,router:f})),w=()=>t.createElement(c,{client:y},t.createElement(a,{router:f}));return n&&"1"!==p.dataset.forceSpa?e.hydrateRoot(p,t.createElement(w,null)):e.createRoot(p).render(t.createElement(w,null))}export{c as default};
2
2
  //# sourceMappingURL=entry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entry.js","sources":["../../src/browser/entry.tsx"],"sourcesContent":["import type { Router as RemixRouter } from '@remix-run/router/dist/router';\nimport type { FC, PropsWithChildren } from 'react';\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport type { RouteObject } from 'react-router-dom';\nimport { createBrowserRouter, matchRoutes, RouterProvider } from 'react-router-dom';\nimport { IS_SSR_MODE } from '@constants/common';\nimport type { TRouteObject } from '@interfaces/route-object';\n\nexport interface IAppClientProps<T = undefined> {\n client: T;\n}\n\nexport interface IInitPropsParams {\n isSSRMode: boolean;\n router: RemixRouter;\n}\n\nexport type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;\n\nexport interface IEntryClientOptions<T> {\n init?: (params: IInitPropsParams) => Promise<T>;\n routerOptions?: Parameters<typeof createBrowserRouter>[1];\n rootId?: string;\n}\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n App: TApp<TAppProps>,\n routes: TRouteObject[],\n { init, routerOptions, rootId = 'root' }: IEntryClientOptions<TAppProps> = {},\n): Promise<ReactDOM.Root | void> {\n const lazyMatches = matchRoutes(routes as RouteObject[], window.location)?.filter(\n (m) => m.route.lazy,\n );\n\n // Load the lazy matches and update the routes before creating router,\n // so we can hydrate the SSR-rendered content synchronously\n if (lazyMatches && lazyMatches?.length > 0) {\n await Promise.all(\n lazyMatches.map(async (m) => {\n const routeModule = await m.route.lazy?.();\n\n Object.assign(m.route, {\n ...routeModule,\n lazy: undefined,\n });\n }),\n );\n }\n\n const router = createBrowserRouter(routes as RouteObject[], routerOptions);\n const root = document.getElementById(rootId) as HTMLElement;\n const appProps = (await init?.({ isSSRMode: IS_SSR_MODE, router })) as TAppProps;\n\n const AppComponent: FC = () => (\n <App client={appProps}>\n <RouterProvider router={router} />\n </App>\n );\n\n if (!IS_SSR_MODE || root.dataset['forceSpa'] === '1') {\n return ReactDOM.createRoot(root).render(<AppComponent />);\n }\n\n return ReactDOM.hydrateRoot(root, <AppComponent />);\n}\n\nexport default entry;\n"],"names":["async","entry","App","routes","init","routerOptions","rootId","lazyMatches","matchRoutes","window","location","filter","m","route","lazy","length","Promise","all","map","routeModule","Object","assign","undefined","router","createBrowserRouter","root","document","getElementById","appProps","isSSRMode","IS_SSR_MODE","AppComponent","React","createElement","client","RouterProvider","dataset","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"sMA6BAA,eAAeC,EACbC,EACAC,GACAC,KAAEA,EAAIC,cAAEA,EAAaC,OAAEA,EAAS,QAA2C,IAE3E,MAAMC,EAAcC,EAAYL,EAAyBM,OAAOC,WAAWC,QACxEC,GAAMA,EAAEC,MAAMC,OAKbP,GAAeA,GAAaQ,OAAS,SACjCC,QAAQC,IACZV,EAAYW,KAAIlB,MAAOY,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,EAASC,EAAoBrB,EAAyBE,GACtDoB,EAAOC,SAASC,eAAerB,GAC/BsB,QAAkBxB,IAAO,CAAEyB,UAAWC,EAAaP,YAEnDQ,EAAmB,IACvBC,EAAAC,cAAC/B,EAAG,CAACgC,OAAQN,GACXI,EAACC,cAAAE,GAAeZ,OAAQA,KAI5B,OAAKO,GAA4C,MAA7BL,EAAKW,QAAkB,SAIpCC,EAASC,YAAYb,EAAMO,EAACC,cAAAF,EAAe,OAHzCM,EAASE,WAAWd,GAAMe,OAAOR,EAAAC,cAACF,EAAY,MAIzD"}
1
+ {"version":3,"file":"entry.js","sources":["../../src/browser/entry.tsx"],"sourcesContent":["import type { Router as RemixRouter } from '@remix-run/router/dist/router';\nimport type { FC, PropsWithChildren } from 'react';\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport type { RouteObject } from 'react-router-dom';\nimport { createBrowserRouter, matchRoutes, RouterProvider } from 'react-router-dom';\nimport { IS_SSR_MODE } from '@constants/common';\nimport type { TRouteObject } from '@interfaces/route-object';\n\nexport interface IAppClientProps<T = undefined> {\n client: T;\n}\n\nexport interface IInitPropsParams {\n isSSRMode: boolean;\n router: RemixRouter;\n}\n\nexport type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;\n\nexport interface IEntryClientOptions<T> {\n init?: (params: IInitPropsParams) => Promise<T>;\n routerOptions?: Parameters<typeof createBrowserRouter>[1];\n createRouter?: typeof createBrowserRouter;\n rootId?: string;\n}\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n App: TApp<TAppProps>,\n routes: TRouteObject[],\n {\n init,\n routerOptions,\n createRouter = createBrowserRouter,\n rootId = 'root',\n }: IEntryClientOptions<TAppProps> = {},\n): Promise<ReactDOM.Root | void> {\n const lazyMatches = matchRoutes(routes as RouteObject[], window.location)?.filter(\n (m) => m.route.lazy,\n );\n\n // Load the lazy matches and update the routes before creating router,\n // so we can hydrate the SSR-rendered content synchronously\n if (lazyMatches && lazyMatches?.length > 0) {\n await Promise.all(\n lazyMatches.map(async (m) => {\n const routeModule = await m.route.lazy?.();\n\n Object.assign(m.route, {\n ...routeModule,\n lazy: undefined,\n });\n }),\n );\n }\n\n const router = createRouter(routes as RouteObject[], routerOptions);\n const root = document.getElementById(rootId) as HTMLElement;\n const appProps = (await init?.({ isSSRMode: IS_SSR_MODE, router })) as TAppProps;\n\n const AppComponent: FC = () => (\n <App client={appProps}>\n <RouterProvider router={router} />\n </App>\n );\n\n if (!IS_SSR_MODE || root.dataset['forceSpa'] === '1') {\n return ReactDOM.createRoot(root).render(<AppComponent />);\n }\n\n return ReactDOM.hydrateRoot(root, <AppComponent />);\n}\n\nexport default entry;\n"],"names":["async","entry","App","routes","init","routerOptions","createRouter","createBrowserRouter","rootId","lazyMatches","matchRoutes","window","location","filter","m","route","lazy","length","Promise","all","map","routeModule","Object","assign","undefined","router","root","document","getElementById","appProps","isSSRMode","IS_SSR_MODE","AppComponent","React","createElement","client","RouterProvider","dataset","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"sMA8BAA,eAAeC,EACbC,EACAC,GACAC,KACEA,EAAIC,cACJA,EAAaC,aACbA,EAAeC,EAAmBC,OAClCA,EAAS,QACyB,CAAA,GAEpC,MAAMC,EAAcC,EAAYP,EAAyBQ,OAAOC,WAAWC,QACxEC,GAAMA,EAAEC,MAAMC,OAKbP,GAAeA,GAAaQ,OAAS,SACjCC,QAAQC,IACZV,EAAYW,KAAIpB,MAAOc,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,EAASnB,EAAaH,EAAyBE,GAC/CqB,EAAOC,SAASC,eAAepB,GAC/BqB,QAAkBzB,IAAO,CAAE0B,UAAWC,EAAaN,YAEnDO,EAAmB,IACvBC,EAAAC,cAAChC,EAAG,CAACiC,OAAQN,GACXI,EAACC,cAAAE,GAAeX,OAAQA,KAI5B,OAAKM,GAA4C,MAA7BL,EAAKW,QAAkB,SAIpCC,EAASC,YAAYb,EAAMO,EAACC,cAAAF,EAAe,OAHzCM,EAASE,WAAWd,GAAMe,OAAOR,EAAAC,cAACF,EAAY,MAIzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/vite-ssr-boost",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Vite plugin for create awesome SSR or SPA applications on React.",
5
5
  "type": "module",
6
6
  "keywords": [