lovable-ssr 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -81,20 +81,22 @@ export async function render(url: string) {
81
81
 
82
82
  ### 4. SSR server (optional)
83
83
 
84
- Run the Express + Vite server using the framework’s `createServer` (import from the `server` subpath so Node-only code is not bundled in the client):
84
+ Run the Express + Vite server using the framework’s `createServer` (import from the `server` subpath so Node-only code is not bundled in the client). **You must import your routes module before `createServer()`** so the route registry is filled when the server starts; otherwise `isSsrRoute(pathname)` sees an empty list and every request is treated as SPA.
85
85
 
86
86
  ```ts
87
87
  // src/ssr/server.ts
88
88
  import path from 'node:path';
89
89
  import { fileURLToPath } from 'node:url';
90
90
  import { createServer } from 'lovable-ssr/server';
91
+ // Ensures the route registry is populated before the first request (isSsrRoute, etc.)
92
+ import '../application/routes'; // or '@/routes' depending on your path aliases
91
93
 
92
94
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
93
95
  const root = path.resolve(__dirname, '../..');
94
96
 
95
97
  createServer({
96
98
  root,
97
- entryPath: 'src/entry-server.tsx',
99
+ entryPath: 'src/ssr/entry-server.tsx',
98
100
  port: process.env.PORT ? Number(process.env.PORT) : 5173,
99
101
  })
100
102
  .then((s) => s.listen())
@@ -8,10 +8,10 @@ export function buildRouteKey(path, params) {
8
8
  }
9
9
  const RouteDataContext = createContext(null);
10
10
  export function RouteDataProvider({ children, initialData, initialRoute, initialParams = {}, }) {
11
- const initialKey = initialRoute && initialData !== undefined
11
+ const initialKey = initialRoute && Object.keys(initialData ?? {}).length > 0
12
12
  ? buildRouteKey(initialRoute.path, initialParams)
13
13
  : null;
14
- const [data, setDataState] = useState(() => initialKey !== null && initialData !== undefined ? { [initialKey]: initialData } : {});
14
+ const [data, setDataState] = useState(() => initialKey && initialData ? { [initialKey]: initialData } : {});
15
15
  const setData = useCallback((routeKey, value) => {
16
16
  setDataState((prev) => ({ ...prev, [routeKey]: value }));
17
17
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lovable-ssr",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "SSR and route data engine for Lovable projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",