@lomray/vite-ssr-boost 2.1.0 → 2.2.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.
@@ -2,6 +2,7 @@
2
2
  import { Router as RemixRouter } from '@remix-run/router/dist/router';
3
3
  import { FC, PropsWithChildren } from 'react';
4
4
  import ReactDOM from 'react-dom/client';
5
+ import { createBrowserRouter } from 'react-router-dom';
5
6
  import { TRouteObject } from "../interfaces/route-object.js";
6
7
  interface IAppClientProps<T = undefined> {
7
8
  client: T;
@@ -13,9 +14,11 @@ interface IInitPropsParams {
13
14
  type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;
14
15
  interface IEntryClientOptions<T> {
15
16
  init?: (params: IInitPropsParams) => Promise<T>;
17
+ routerOptions?: Parameters<typeof createBrowserRouter>[1];
18
+ rootId?: string;
16
19
  }
17
20
  /**
18
21
  * Render client side application
19
22
  */
20
- declare function entry<TAppProps>(App: TApp<TAppProps>, routes: TRouteObject[], { init }?: IEntryClientOptions<TAppProps>): Promise<ReactDOM.Root | void>;
23
+ declare function entry<TAppProps>(App: TApp<TAppProps>, routes: TRouteObject[], { init, routerOptions, rootId }?: IEntryClientOptions<TAppProps>): Promise<ReactDOM.Root | void>;
21
24
  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,l,{init:m}={}){const i=o(l,window.location)?.filter((t=>t.route.lazy));i&&i?.length>0&&await Promise.all(i.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const s=r(l),u=document.getElementById("root"),d=await(m?.({isSSRMode:n,router:s})),f=()=>t.createElement(c,{client:d},t.createElement(a,{router:s}));return n?e.hydrateRoot(u,t.createElement(f,null)):e.createRoot(u).render(t.createElement(f,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 n}from"react-router-dom";import{IS_SSR_MODE as a}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:a,router:d})),y=()=>t.createElement(c,{client:p},t.createElement(n,{router:d}));return a?e.hydrateRoot(f,t.createElement(y,null)):e.createRoot(f).render(t.createElement(y,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}\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n App: TApp<TAppProps>,\n routes: TRouteObject[],\n { init }: 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[]);\n const root = document.getElementById('root') 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) {\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","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","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"sMA2BAA,eAAeC,EACbC,EACAC,GACAC,KAAEA,GAAyC,CAAA,GAE3C,MAAMC,EAAcC,EAAYH,EAAyBI,OAAOC,WAAWC,QACxEC,GAAMA,EAAEC,MAAMC,OAKbP,GAAeA,GAAaQ,OAAS,SACjCC,QAAQC,IACZV,EAAYW,KAAIhB,MAAOU,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,EAASC,EAAoBnB,GAC7BoB,EAAOC,SAASC,eAAe,QAC/BC,QAAkBtB,IAAO,CAAEuB,UAAWC,EAAaP,YAEnDQ,EAAmB,IACvBC,EAAAC,cAAC7B,EAAG,CAAC8B,OAAQN,GACXI,EAACC,cAAAE,GAAeZ,OAAQA,KAI5B,OAAKO,EAIEM,EAASC,YAAYZ,EAAMO,EAACC,cAAAF,EAAe,OAHzCK,EAASE,WAAWb,GAAMc,OAAOP,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 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) {\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","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,EAIEM,EAASC,YAAYZ,EAAMO,EAACC,cAAAF,EAAe,OAHzCK,EAASE,WAAWb,GAAMc,OAAOP,EAAAC,cAACF,EAAY,MAIzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/vite-ssr-boost",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Vite plugin for create awesome SSR or SPA applications on React.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -46,6 +46,7 @@
46
46
  "@lomray/eslint-config": "^4.0.1",
47
47
  "@lomray/prettier-config": "^2.0.1",
48
48
  "@rollup/plugin-terser": "^0.4.4",
49
+ "@testing-library/react": "^14.1.2",
49
50
  "@types/chai": "^4.3.11",
50
51
  "@types/compression": "^1.7.5",
51
52
  "@types/hjson": "^2.4.6",
@@ -63,6 +64,7 @@
63
64
  "eslint-plugin-jsx-a11y": "^6.8.0",
64
65
  "eslint-plugin-prettier": "^5.0.1",
65
66
  "husky": "^8.0.3",
67
+ "jsdom": "^24.0.0",
66
68
  "lint-staged": "^15.2.0",
67
69
  "prettier": "^3.1.1",
68
70
  "rollup": "^4.9.0",