@lomray/vite-ssr-boost 2.8.0 → 2.8.1

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.
@@ -6,10 +6,11 @@ interface IOnlyClient<T> {
6
6
  children: (Component: ComponentType<T>) => ReactNode;
7
7
  fallback?: ReactNode;
8
8
  errorComponent?: ReactNode;
9
+ isMemorized?: boolean;
9
10
  }
10
11
  /**
11
12
  * Render component only on client side
12
13
  * @constructor
13
14
  */
14
- declare function OnlyClient<T>({ load, children, fallback, errorComponent, }: IOnlyClient<T>): ReactNode;
15
+ declare function OnlyClient<T>({ load, children, fallback, errorComponent, isMemorized, }: IOnlyClient<T>): ReactNode;
15
16
  export { OnlyClient as default };
@@ -1,2 +1,2 @@
1
- import e,{useState as t,useEffect as l,startTransition as n,lazy as o}from"react";const a=e.createElement("p",null,"Failed to load client side component.");function c({load:c,children:r,fallback:d,errorComponent:i=a}){const[u,f]=t(null);return l((()=>{n((()=>{const e=o((()=>c().then((e=>({default:()=>r("default"in e?e.default:e)}))).catch((e=>(console.error("Client side component loading failed:",e),{default:()=>i})))));f(e)}))}),[]),u?e.createElement(u,null):d}export{c as default};
1
+ import e,{useState as t,useEffect as l,startTransition as n,lazy as o}from"react";const a=e.createElement("p",null,"Failed to load client side component.");function r({load:r,children:c,fallback:d,errorComponent:i=a,isMemorized:u=!1}){const[f,m]=t(null);return l((()=>{n((()=>{const e=o((()=>r().then((e=>({default:()=>c("default"in e?e.default:e)}))).catch((e=>(console.error("Client side component loading failed:",e),{default:()=>i})))));m(e)}))}),[!!u||c]),f?e.createElement(f,null):d}export{r as default};
2
2
  //# sourceMappingURL=only-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"only-client.js","sources":["../../src/components/only-client.tsx"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport React, { lazy, startTransition, useEffect, useState } from 'react';\n\ninterface IOnlyClient<T> {\n load: () => Promise<{ default: ComponentType<T> } | ComponentType<T>>;\n children: (Component: ComponentType<T>) => ReactNode;\n fallback?: ReactNode;\n errorComponent?: ReactNode;\n}\n\nconst defaultError = <p>Failed to load client side component.</p>;\n\n/**\n * Render component only on client side\n * @constructor\n */\nfunction OnlyClient<T>({\n load,\n children,\n fallback,\n errorComponent = defaultError,\n}: IOnlyClient<T>): ReactNode {\n const [Component, setComponent] = useState<ComponentType<unknown> | null>(null);\n\n useEffect(() => {\n startTransition(() => {\n const LoadedComponent = lazy(() =>\n load()\n .then((Loaded) => ({\n default: () => children('default' in Loaded ? Loaded.default : Loaded),\n }))\n .catch((error: Error) => {\n console.error('Client side component loading failed:', error);\n\n return { default: () => errorComponent };\n }),\n );\n\n setComponent(LoadedComponent);\n });\n }, []);\n\n return Component ? <Component /> : fallback;\n}\n\nexport default OnlyClient;\n"],"names":["defaultError","React","createElement","OnlyClient","load","children","fallback","errorComponent","Component","setComponent","useState","useEffect","startTransition","LoadedComponent","lazy","then","Loaded","default","catch","error","console"],"mappings":"kFAUA,MAAMA,EAAeC,EAAAC,cAAA,IAAA,KAAA,yCAMrB,SAASC,GAAcC,KACrBA,EAAIC,SACJA,EAAQC,SACRA,EAAQC,eACRA,EAAiBP,IAEjB,MAAOQ,EAAWC,GAAgBC,EAAwC,MAoB1E,OAlBAC,GAAU,KACRC,GAAgB,KACd,MAAMC,EAAkBC,GAAK,IAC3BV,IACGW,MAAMC,IAAY,CACjBC,QAAS,IAAMZ,EAAS,YAAaW,EAASA,EAAOC,QAAUD,OAEhEE,OAAOC,IACNC,QAAQD,MAAM,wCAAyCA,GAEhD,CAAEF,QAAS,IAAMV,QAI9BE,EAAaI,EAAgB,GAC7B,GACD,IAEIL,EAAYP,EAAAC,cAACM,EAAS,MAAMF,CACrC"}
1
+ {"version":3,"file":"only-client.js","sources":["../../src/components/only-client.tsx"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react';\nimport React, { lazy, startTransition, useEffect, useState } from 'react';\n\ninterface IOnlyClient<T> {\n load: () => Promise<{ default: ComponentType<T> } | ComponentType<T>>;\n children: (Component: ComponentType<T>) => ReactNode;\n fallback?: ReactNode;\n errorComponent?: ReactNode;\n isMemorized?: boolean;\n}\n\nconst defaultError = <p>Failed to load client side component.</p>;\n\n/**\n * Render component only on client side\n * @constructor\n */\nfunction OnlyClient<T>({\n load,\n children,\n fallback,\n errorComponent = defaultError,\n isMemorized = false,\n}: IOnlyClient<T>): ReactNode {\n const [Component, setComponent] = useState<ComponentType<unknown> | null>(null);\n\n useEffect(() => {\n startTransition(() => {\n const LoadedComponent = lazy(() =>\n load()\n .then((Loaded) => ({\n default: () => children('default' in Loaded ? Loaded.default : Loaded),\n }))\n .catch((error: Error) => {\n console.error('Client side component loading failed:', error);\n\n return { default: () => errorComponent };\n }),\n );\n\n setComponent(LoadedComponent);\n });\n }, [isMemorized ? true : children]);\n\n return Component ? <Component /> : fallback;\n}\n\nexport default OnlyClient;\n"],"names":["defaultError","React","createElement","OnlyClient","load","children","fallback","errorComponent","isMemorized","Component","setComponent","useState","useEffect","startTransition","LoadedComponent","lazy","then","Loaded","default","catch","error","console"],"mappings":"kFAWA,MAAMA,EAAeC,EAAAC,cAAA,IAAA,KAAA,yCAMrB,SAASC,GAAcC,KACrBA,EAAIC,SACJA,EAAQC,SACRA,EAAQC,eACRA,EAAiBP,EAAYQ,YAC7BA,GAAc,IAEd,MAAOC,EAAWC,GAAgBC,EAAwC,MAoB1E,OAlBAC,GAAU,KACRC,GAAgB,KACd,MAAMC,EAAkBC,GAAK,IAC3BX,IACGY,MAAMC,IAAY,CACjBC,QAAS,IAAMb,EAAS,YAAaY,EAASA,EAAOC,QAAUD,OAEhEE,OAAOC,IACNC,QAAQD,MAAM,wCAAyCA,GAEhD,CAAEF,QAAS,IAAMX,QAI9BG,EAAaI,EAAgB,GAC7B,GACD,GAACN,GAAqBH,IAElBI,EAAYR,EAAAC,cAACO,EAAS,MAAMH,CACrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sources":["../../src/constants/common.ts"],"sourcesContent":["/* eslint-disable no-undef */\n// @ts-ignore\nconst IS_SSR_MODE = (typeof __IS_SSR__ === 'undefined' ? true : __IS_SSR__) as boolean; // build in SSR mode?\n\n// eslint-disable-next-line import/prefer-default-export\nexport { IS_SSR_MODE };\n"],"names":["IS_SSR_MODE","__IS_SSR__"],"mappings":"AAEA,MAAMA,EAAqC,oBAAfC,YAAoCA"}
1
+ {"version":3,"file":"common.js","sources":["../../src/constants/common.ts"],"sourcesContent":["/* eslint-disable no-undef */\n// @ts-ignore\nconst IS_SSR_MODE = (typeof __IS_SSR__ === 'undefined' ? true : __IS_SSR__) as boolean; // build in SSR mode?\n\n// const IS_SERVER = typeof window === 'undefined';\n\n// eslint-disable-next-line import/prefer-default-export\nexport { IS_SSR_MODE };\n"],"names":["IS_SSR_MODE","__IS_SSR__"],"mappings":"AAEA,MAAMA,EAAqC,oBAAfC,YAAoCA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/vite-ssr-boost",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "description": "Vite plugin for create awesome SSR or SPA applications on React.",
5
5
  "type": "module",
6
6
  "keywords": [