lovable-ssr 0.1.11 → 0.1.12
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/dist/components/AppRoutes.js +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/ssr/render.d.ts +1 -1
- package/dist/ssr/render.js +5 -5
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -17,23 +17,23 @@ export function AppRoutes() {
|
|
|
17
17
|
const routeKey = matchedRoute ? buildRouteKey(matchedRoute.path, params.routeParams, params.searchParams) : '';
|
|
18
18
|
const { data, setData } = useRouteData();
|
|
19
19
|
const currentData = routeKey ? data[routeKey] : undefined;
|
|
20
|
-
const
|
|
20
|
+
const getData = matchedRoute?.Component?.getData;
|
|
21
21
|
useEffect(() => {
|
|
22
|
-
if (!routeKey || !
|
|
22
|
+
if (!routeKey || !getData || currentData !== undefined)
|
|
23
23
|
return;
|
|
24
|
-
|
|
24
|
+
getData(params)
|
|
25
25
|
.then((d) => setData(routeKey, d))
|
|
26
26
|
.catch((e) => {
|
|
27
|
-
console.error('Client
|
|
27
|
+
console.error('Client getData failed:', e);
|
|
28
28
|
setData(routeKey, {});
|
|
29
29
|
});
|
|
30
|
-
}, [routeKey,
|
|
30
|
+
}, [routeKey, getData, params, currentData, setData]);
|
|
31
31
|
return (_jsx(Routes, { children: routes.map((route) => {
|
|
32
32
|
const isMatched = matchedRoute === route;
|
|
33
|
-
const
|
|
33
|
+
const getDataForRoute = route.Component.getData;
|
|
34
34
|
let element;
|
|
35
35
|
if (isMatched) {
|
|
36
|
-
if (typeof
|
|
36
|
+
if (typeof getDataForRoute === 'function') {
|
|
37
37
|
element =
|
|
38
38
|
currentData !== undefined ? (_jsx(route.Component, { ...currentData })) : null;
|
|
39
39
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './globals.js';
|
|
2
|
-
export type { RouteConfig,
|
|
2
|
+
export type { RouteConfig, ComponentWithGetData } from './types.js';
|
|
3
3
|
export { registerRoutes, getRoutes } from './registry.js';
|
|
4
4
|
export { BrowserRouteDataProvider } from './components/BrowserRouteDataProvider.js';
|
|
5
5
|
export { default as RouterService } from './router/RouterService.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,iBAAiB,CAAC"}
|
package/dist/ssr/render.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface RenderOptions {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Renders the app for a single URL. Called once per request with that request's URL.
|
|
11
|
-
*
|
|
11
|
+
* getData is invoked only for the route that matches this URL (never for all routes).
|
|
12
12
|
*/
|
|
13
13
|
export declare function render(url: string, options?: RenderOptions): Promise<RenderResult>;
|
|
14
14
|
//# sourceMappingURL=render.d.ts.map
|
package/dist/ssr/render.js
CHANGED
|
@@ -6,7 +6,7 @@ import { RouteDataProvider } from '../router/RouteDataContext.js';
|
|
|
6
6
|
import { AppRoutes } from '../components/AppRoutes.js';
|
|
7
7
|
/**
|
|
8
8
|
* Renders the app for a single URL. Called once per request with that request's URL.
|
|
9
|
-
*
|
|
9
|
+
* getData is invoked only for the route that matches this URL (never for all routes).
|
|
10
10
|
*/
|
|
11
11
|
export async function render(url, options) {
|
|
12
12
|
const fullUrl = new URL(url, 'http://localhost');
|
|
@@ -19,13 +19,13 @@ export async function render(url, options) {
|
|
|
19
19
|
const searchParams = matchedRoute ? RouterService.searchParams(fullUrl.search) : {};
|
|
20
20
|
params.searchParams = searchParams;
|
|
21
21
|
let preloadedData = { is_success: true };
|
|
22
|
-
const
|
|
23
|
-
if (typeof
|
|
22
|
+
const getData = matchedRoute?.Component?.getData;
|
|
23
|
+
if (typeof getData === 'function') {
|
|
24
24
|
try {
|
|
25
|
-
preloadedData = await
|
|
25
|
+
preloadedData = await getData(params);
|
|
26
26
|
}
|
|
27
27
|
catch (e) {
|
|
28
|
-
console.error(`SSR
|
|
28
|
+
console.error(`SSR getData failed for ${matchedRoute?.path}:`, e);
|
|
29
29
|
preloadedData = { ...preloadedData, is_success: false };
|
|
30
30
|
}
|
|
31
31
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
export type
|
|
3
|
-
|
|
2
|
+
export type ComponentWithGetData = React.ComponentType<any> & {
|
|
3
|
+
getData?: (params?: Record<'routeParams' | 'searchParams', Record<string, string>>) => Promise<Record<string, unknown>>;
|
|
4
4
|
};
|
|
5
5
|
export type RouteConfig = {
|
|
6
6
|
path: string;
|
|
7
|
-
Component:
|
|
7
|
+
Component: ComponentWithGetData;
|
|
8
8
|
isSSR: boolean;
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG;IAC5D,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,aAAa,GAAG,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACzH,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,oBAAoB,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lovable-ssr",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "SSR and route data engine for Lovable projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ssr",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"vite",
|
|
9
9
|
"express",
|
|
10
10
|
"lovable",
|
|
11
|
-
"
|
|
11
|
+
"getData",
|
|
12
12
|
"route-registry",
|
|
13
13
|
"server-side-rendering"
|
|
14
14
|
],
|