@lomray/vite-ssr-boost 3.3.0 → 3.3.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.
- package/helpers/build-custom-state.js +1 -1
- package/helpers/build-custom-state.js.map +1 -1
- package/helpers/build-router-state.js +1 -1
- package/helpers/build-router-state.js.map +1 -1
- package/helpers/html-escape.d.ts +6 -0
- package/helpers/html-escape.js +2 -0
- package/helpers/html-escape.js.map +1 -0
- package/helpers/serialize-errors.d.ts +1 -0
- package/helpers/serialize-errors.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
import t from"./html-escape.js";function r(r){return Object.entries(r??{}).map((([r,e])=>{if(!r||!e||!Object.keys(e||{}).length)return"";return`<script async>window.${r} = JSON.parse(${t(JSON.stringify(JSON.stringify(e)))});<\/script>`})).join("").trim()}export{r as default};
|
|
2
2
|
//# sourceMappingURL=build-custom-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-custom-state.js","sources":["../../src/helpers/build-custom-state.ts"],"sourcesContent":["import type { IRenderOptions } from '@node/render';\n\n/**\n * Build custom state\n */\nfunction buildCustomState(initState?: ReturnType<NonNullable<IRenderOptions['getState']>>): string {\n const stateScripts = Object.entries(initState ?? {}).map(([key, state]) => {\n if (!key || !state || !Object.keys(state || {}).length) {\n return '';\n }\n\n return `<script async>window.${key} =
|
|
1
|
+
{"version":3,"file":"build-custom-state.js","sources":["../../src/helpers/build-custom-state.ts"],"sourcesContent":["import htmlEscape from '@helpers/html-escape';\nimport type { IRenderOptions } from '@node/render';\n\n/**\n * Build custom state\n */\nfunction buildCustomState(initState?: ReturnType<NonNullable<IRenderOptions['getState']>>): string {\n const stateScripts = Object.entries(initState ?? {}).map(([key, state]) => {\n if (!key || !state || !Object.keys(state || {}).length) {\n return '';\n }\n\n const json = htmlEscape(JSON.stringify(JSON.stringify(state)));\n\n return `<script async>window.${key} = JSON.parse(${json});</script>`;\n });\n\n return stateScripts.join('').trim();\n}\n\nexport default buildCustomState;\n"],"names":["buildCustomState","initState","Object","entries","map","key","state","keys","length","htmlEscape","JSON","stringify","join","trim"],"mappings":"gCAMA,SAASA,EAAiBC,GAWxB,OAVqBC,OAAOC,QAAQF,GAAa,CAAA,GAAIG,KAAI,EAAEC,EAAKC,MAC9D,IAAKD,IAAQC,IAAUJ,OAAOK,KAAKD,GAAS,IAAIE,OAC9C,MAAO,GAKT,MAAO,wBAAwBH,kBAFlBI,EAAWC,KAAKC,UAAUD,KAAKC,UAAUL,kBAEc,IAGlDM,KAAK,IAAIC,MAC/B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import r from"./serialize-errors.js";function a(a){const{loaderData:
|
|
1
|
+
import r from"./html-escape.js";import t from"./serialize-errors.js";function a(a){const{loaderData:o,actionData:i,errors:s}=a,e={loaderData:o,actionData:i,errors:t(s)};return`<script async>window.__staticRouterHydrationData = JSON.parse(${r(JSON.stringify(JSON.stringify(e)))});<\/script>`}export{a as default};
|
|
2
2
|
//# sourceMappingURL=build-router-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-router-state.js","sources":["../../src/helpers/build-router-state.ts"],"sourcesContent":["import type { StaticHandlerContext } from 'react-router-dom/server';\nimport serializeErrors from '@helpers/serialize-errors';\n\n/**\n * Build router state\n */\nfunction buildRouterState(context: StaticHandlerContext): string {\n const { loaderData, actionData, errors } = context;\n const routerState = {\n loaderData,\n actionData,\n errors: serializeErrors(errors),\n };\n const json = JSON.stringify(routerState);\n\n return `<script async>window.__staticRouterHydrationData = ${json};</script>`;\n}\n\nexport default buildRouterState;\n"],"names":["buildRouterState","context","loaderData","actionData","errors","routerState","serializeErrors","JSON","stringify"],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-router-state.js","sources":["../../src/helpers/build-router-state.ts"],"sourcesContent":["import type { StaticHandlerContext } from 'react-router-dom/server';\nimport htmlEscape from '@helpers/html-escape';\nimport serializeErrors from '@helpers/serialize-errors';\n\n/**\n * Build router state\n */\nfunction buildRouterState(context: StaticHandlerContext): string {\n const { loaderData, actionData, errors } = context;\n const routerState = {\n loaderData,\n actionData,\n errors: serializeErrors(errors),\n };\n const json = htmlEscape(JSON.stringify(JSON.stringify(routerState)));\n\n return `<script async>window.__staticRouterHydrationData = JSON.parse(${json});</script>`;\n}\n\nexport default buildRouterState;\n"],"names":["buildRouterState","context","loaderData","actionData","errors","routerState","serializeErrors","htmlEscape","JSON","stringify"],"mappings":"qEAOA,SAASA,EAAiBC,GACxB,MAAMC,WAAEA,EAAUC,WAAEA,EAAUC,OAAEA,GAAWH,EACrCI,EAAc,CAClBH,aACAC,aACAC,OAAQE,EAAgBF,IAI1B,MAAO,iEAFMG,EAAWC,KAAKC,UAAUD,KAAKC,UAAUJ,kBAGxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-escape.js","sources":["../../src/helpers/html-escape.ts"],"sourcesContent":["const ESCAPE_LOOKUP: { [match: string]: string } = {\n '&': '\\\\u0026',\n '>': '\\\\u003e',\n '<': '\\\\u003c',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n};\nconst ESCAPE_REGEX = /[&><\\u2028\\u2029]/g;\n\n/**\n * This utility is based on https://github.com/zertosh/htmlescape\n * License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE\n */\nconst htmlEscape = (str: string): string => {\n return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);\n};\n\nexport default htmlEscape;\n"],"names":["ESCAPE_LOOKUP","ESCAPE_REGEX","htmlEscape","str","replace","match"],"mappings":"AAAA,MAAMA,EAA6C,CACjD,IAAK,UACL,IAAK,UACL,IAAK,UACL,SAAU,UACV,SAAU,WAENC,EAAe,qBAMfC,EAAcC,GACXA,EAAIC,QAAQH,GAAeI,GAAUL,EAAcK"}
|
|
@@ -2,6 +2,7 @@ import { StaticHandlerContext } from 'react-router-dom/server';
|
|
|
2
2
|
/**
|
|
3
3
|
* Serialize react router errors
|
|
4
4
|
* @see https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/server.tsx#LL166C1-L188C2
|
|
5
|
+
* https://github.com/remix-run/react-router/blob/main/LICENSE.md
|
|
5
6
|
*/
|
|
6
7
|
declare function serializeErrors(errors: StaticHandlerContext['errors']): StaticHandlerContext['errors'];
|
|
7
8
|
export { serializeErrors as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-errors.js","sources":["../../src/helpers/serialize-errors.ts"],"sourcesContent":["import { isRouteErrorResponse } from 'react-router-dom';\nimport type { StaticHandlerContext } from 'react-router-dom/server';\n\n/**\n * Serialize react router errors\n * @see https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/server.tsx#LL166C1-L188C2\n */\nfunction serializeErrors(errors: StaticHandlerContext['errors']): StaticHandlerContext['errors'] {\n if (!errors) {\n return null;\n }\n\n const entries = Object.entries(errors);\n const serialized: StaticHandlerContext['errors'] = {};\n for (const [key, val] of entries) {\n // Hey you! If you change this, please change the corresponding logic in\n // deserializeErrors in react-router-dom/index.tsx :)\n if (isRouteErrorResponse(val)) {\n serialized[key] = { ...val, __type: 'RouteErrorResponse' };\n } else if (val instanceof Error) {\n // Do not serialize stack traces from SSR for security reasons\n serialized[key] = {\n message: val.message,\n __type: 'Error',\n };\n } else {\n serialized[key] = val as unknown;\n }\n }\n\n return serialized;\n}\n\nexport default serializeErrors;\n"],"names":["serializeErrors","errors","entries","Object","serialized","key","val","isRouteErrorResponse","__type","Error","message"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serialize-errors.js","sources":["../../src/helpers/serialize-errors.ts"],"sourcesContent":["import { isRouteErrorResponse } from 'react-router-dom';\nimport type { StaticHandlerContext } from 'react-router-dom/server';\n\n/**\n * Serialize react router errors\n * @see https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/server.tsx#LL166C1-L188C2\n * https://github.com/remix-run/react-router/blob/main/LICENSE.md\n */\nfunction serializeErrors(errors: StaticHandlerContext['errors']): StaticHandlerContext['errors'] {\n if (!errors) {\n return null;\n }\n\n const entries = Object.entries(errors);\n const serialized: StaticHandlerContext['errors'] = {};\n for (const [key, val] of entries) {\n // Hey you! If you change this, please change the corresponding logic in\n // deserializeErrors in react-router-dom/index.tsx :)\n if (isRouteErrorResponse(val)) {\n serialized[key] = { ...val, __type: 'RouteErrorResponse' };\n } else if (val instanceof Error) {\n // Do not serialize stack traces from SSR for security reasons\n serialized[key] = {\n message: val.message,\n __type: 'Error',\n };\n } else {\n serialized[key] = val as unknown;\n }\n }\n\n return serialized;\n}\n\nexport default serializeErrors;\n"],"names":["serializeErrors","errors","entries","Object","serialized","key","val","isRouteErrorResponse","__type","Error","message"],"mappings":"wDAQA,SAASA,EAAgBC,GACvB,IAAKA,EACH,OAAO,KAGT,MAAMC,EAAUC,OAAOD,QAAQD,GACzBG,EAA6C,CAAA,EACnD,IAAK,MAAOC,EAAKC,KAAQJ,EAGnBK,EAAqBD,GACvBF,EAAWC,GAAO,IAAKC,EAAKE,OAAQ,sBAC3BF,aAAeG,MAExBL,EAAWC,GAAO,CAChBK,QAASJ,EAAII,QACbF,OAAQ,SAGVJ,EAAWC,GAAOC,EAItB,OAAOF,CACT"}
|