@lowdefy/server-dev 0.0.0-experimental-20260807075508 → 0.0.0-experimental-20260813120102

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.
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import React, { useEffect, useRef } from 'react';
17
+ import React, { useEffect, useRef, useState } from 'react';
18
18
  import { createAuthClient } from 'better-auth/react';
19
19
  import {
20
20
  adminClient,
@@ -66,9 +66,11 @@ const sessionScoped = (params) => ({
66
66
  //
67
67
  // Roles and merged attributes resolve server-side from the active member row
68
68
  // - the base session carries neither. The last server-resolved caller is
69
- // kept in a ref: while the session user is unchanged it stays authoritative
70
- // for the fields the session does not carry, and UpdateSession refreshes the
71
- // ref from /api/user after a change (e.g. SetActiveOrganization).
69
+ // held in state: while the session user is unchanged it stays authoritative
70
+ // for the fields the session does not carry, and UpdateSession refreshes it
71
+ // from /api/user after a change (e.g. SetActiveOrganization). Holding it in
72
+ // state, not a ref, re-renders Session when it changes so _user recomputes -
73
+ // the same reactive footing the session half already stands on.
72
74
  //
73
75
  // Only the session half is passed through normalizeCaller. BetterAuth's store
74
76
  // returns camelCase keys whatever the columns are named, so untransformed it
@@ -76,7 +78,7 @@ const sessionScoped = (params) => ({
76
78
  // object; anything arriving from the server is already snake_case.
77
79
  function Session({ children, reloadSuppressedRef, serverUser }) {
78
80
  const { data: session, isPending } = authClient.useSession();
79
- const resolvedUserRef = useRef(serverUser);
81
+ const [resolvedUser, setResolvedUser] = useState(serverUser);
80
82
  const wasAuthenticated = useRef(Boolean(serverUser));
81
83
 
82
84
  useEffect(() => {
@@ -93,14 +95,14 @@ function Session({ children, reloadSuppressedRef, serverUser }) {
93
95
  }, [session, isPending]);
94
96
 
95
97
  if (isPending) {
96
- return children(resolvedUserRef.current, resolvedUserRef);
98
+ return children(resolvedUser, setResolvedUser);
97
99
  }
98
100
  if (!session?.user) {
99
- return children(null, resolvedUserRef);
101
+ return children(null, setResolvedUser);
100
102
  }
101
- const resolved = resolvedUserRef.current;
103
+ const resolved = resolvedUser;
102
104
  if (!resolved) {
103
- return children({ roles: [], ...normalizeCaller(session.user) }, resolvedUserRef);
105
+ return children({ roles: [], ...normalizeCaller(session.user) }, setResolvedUser);
104
106
  }
105
107
  if (resolved.id !== session.user.id) {
106
108
  // The ref has not caught up with a changed session user - a sign-in as a
@@ -112,15 +114,15 @@ function Session({ children, reloadSuppressedRef, serverUser }) {
112
114
  // the window when it lands the new caller; a flow that changes the session
113
115
  // user without chaining it leaves the previous caller rendered until the
114
116
  // next page load.
115
- return children(resolved, resolvedUserRef);
117
+ return children(resolved, setResolvedUser);
116
118
  }
117
119
  // _user is one object with one meaning on both sides: the resolved caller is
118
120
  // spread whole, so every field resolveAuthentication emits is readable in app
119
121
  // config without this file naming it. session.user is the floor - the client
120
- // store may hold a fresher one than the ref, and the resolved object wins
121
- // wherever both carry a key.
122
+ // store may hold a fresher one than the resolved state, and the resolved
123
+ // object wins wherever both carry a key.
122
124
  const user = { ...normalizeCaller(session.user), ...resolved };
123
- return children(user, resolvedUserRef);
125
+ return children(user, setResolvedUser);
124
126
  }
125
127
 
126
128
  function AuthConfigured({ authConfig, children, serverUser }) {
@@ -166,6 +168,7 @@ function AuthConfigured({ authConfig, children, serverUser }) {
166
168
  addPasskey: (params) => authClient.passkey.addPasskey(params),
167
169
  changePassword: (params) => authClient.changePassword(sessionScoped(params)),
168
170
  deletePasskey: (params) => authClient.passkey.deletePasskey(params),
171
+ updatePasskey: (params) => authClient.passkey.updatePasskey(params),
169
172
  leaveOrganization: (params) => authClient.organization.leave(sessionScoped(params)),
170
173
  phoneNumberRequestPasswordReset: (params) =>
171
174
  authClient.phoneNumber.requestPasswordReset(params),
@@ -194,11 +197,9 @@ function AuthConfigured({ authConfig, children, serverUser }) {
194
197
  };
195
198
  return (
196
199
  <Session reloadSuppressedRef={reloadSuppressedRef} serverUser={serverUser}>
197
- {(user, resolvedUserRef) => {
200
+ {(user, setResolvedUser) => {
198
201
  auth.user = user;
199
- auth.updateResolvedUser = (resolved) => {
200
- resolvedUserRef.current = resolved;
201
- };
202
+ auth.updateResolvedUser = (resolved) => setResolvedUser(resolved);
202
203
  return children(auth);
203
204
  }}
204
205
  </Session>
@@ -26,6 +26,7 @@ function AuthNotConfigured({ authConfig, children }) {
26
26
  addPasskey: authNotConfigured,
27
27
  changePassword: authNotConfigured,
28
28
  deletePasskey: authNotConfigured,
29
+ updatePasskey: authNotConfigured,
29
30
  getResolvedUser: authNotConfigured,
30
31
  getSession: authNotConfigured,
31
32
  leaveOrganization: authNotConfigured,
@@ -27,31 +27,7 @@ function parseJsModule(text) {
27
27
  return mod.default ?? {};
28
28
  }
29
29
 
30
- async function fetchJsEntries(basePath) {
31
- try {
32
- const res = await fetch(`${basePath}/api/js/client`, {
33
- signal: AbortSignal.timeout(10_000),
34
- });
35
- if (!res.ok) return {};
36
- return parseJsModule(await res.text());
37
- } catch {
38
- return {};
39
- }
40
- }
41
-
42
- async function fetchDynamicIcons(basePath) {
43
- try {
44
- const res = await fetch(`${basePath}/api/icons/dynamic`, {
45
- signal: AbortSignal.timeout(10_000),
46
- });
47
- if (!res.ok) return {};
48
- return parseJsModule(await res.text());
49
- } catch {
50
- return {};
51
- }
52
- }
53
-
54
- async function fetchPageConfig(url) {
30
+ export async function fetchPageConfig(url) {
55
31
  const basePath = url.replace(/\/api\/page\/.*$/, '');
56
32
  // A stalled request (server restart mid-request, exhausted sockets) must
57
33
  // become a visible error, never an eternal Suspense fallback — the reload
@@ -98,14 +74,11 @@ async function fetchPageConfig(url) {
98
74
  throw new Error(data.message || 'Request error');
99
75
  }
100
76
 
101
- // Fetch jsMap and dynamic icons after page build completes
102
- // (JIT build may have added new entries).
103
- const [jsEntries, dynamicIcons] = await Promise.all([
104
- fetchJsEntries(basePath),
105
- fetchDynamicIcons(basePath),
106
- ]);
107
- data._jsEntries = jsEntries;
108
- data._dynamicIcons = dynamicIcons;
77
+ // The JIT build folds this page's _js entries and dynamic icons into the
78
+ // response, so first paint needs no secondary fetch. _jsEntries arrives as
79
+ // module text — compile it to the { hash: fn } object Page expects.
80
+ // _dynamicIcons is already plain data — leave it for Page to inject.
81
+ if (data._jsEntries) data._jsEntries = parseJsModule(data._jsEntries);
109
82
 
110
83
  if (data?.dynamic === true) {
111
84
  dynamicUrls.add(url);
@@ -0,0 +1,62 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { jest } from '@jest/globals';
18
+
19
+ // usePageConfig imports swr and useMutateCache only for the hook; the fetcher
20
+ // under test needs neither. Mock them so the module loads in the node test env.
21
+ jest.unstable_mockModule('swr', () => ({ default: jest.fn() }));
22
+ jest.unstable_mockModule('./useMutateCache.js', () => ({
23
+ getNavVersion: jest.fn(),
24
+ getReloadVersion: jest.fn(),
25
+ }));
26
+
27
+ const { fetchPageConfig } = await import('./usePageConfig.js');
28
+
29
+ function mockJsonResponse(body) {
30
+ return { status: 200, ok: true, json: async () => body };
31
+ }
32
+
33
+ afterEach(() => {
34
+ delete global.fetch;
35
+ });
36
+
37
+ test('fetchPageConfig compiles inlined _jsEntries module text into a { hash: fn } object', async () => {
38
+ global.fetch = jest.fn(async () =>
39
+ mockJsonResponse({
40
+ id: 'p',
41
+ _jsEntries: "export default { 'h1': ({ args }) => { return args.x + 1; } };",
42
+ _dynamicIcons: { FiZap: { tag: 'svg' } },
43
+ })
44
+ );
45
+
46
+ const data = await fetchPageConfig('http://localhost/api/page/p');
47
+
48
+ expect(typeof data._jsEntries.h1).toBe('function');
49
+ expect(data._jsEntries.h1({ args: { x: 1 } })).toBe(2);
50
+ // _dynamicIcons passes through untouched.
51
+ expect(data._dynamicIcons).toEqual({ FiZap: { tag: 'svg' } });
52
+ });
53
+
54
+ test('fetchPageConfig issues only the page-config request — no /api/js or /api/icons fetch', async () => {
55
+ global.fetch = jest.fn(async () => mockJsonResponse({ id: 'p' }));
56
+
57
+ const data = await fetchPageConfig('http://localhost/api/page/p');
58
+
59
+ expect(data._jsEntries).toBeUndefined();
60
+ expect(global.fetch).toHaveBeenCalledTimes(1);
61
+ expect(global.fetch.mock.calls[0][0]).toBe('http://localhost/api/page/p');
62
+ });
@@ -0,0 +1,105 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { getPageJitEnrichment } from './jitPageBuilder.js';
18
+
19
+ // A stub of cachedBuildContext. getPageJitEnrichment reads jsMap.client and
20
+ // dynamicIconData off it; production omits buildContext so it defaults to the
21
+ // module-private cachedBuildContext.
22
+ function buildContext({ client = {}, dynamicIconData = {} } = {}) {
23
+ return { jsMap: { client, server: {} }, dynamicIconData };
24
+ }
25
+
26
+ test('getPageJitEnrichment scopes string-form, object-form, and args-nested _js hashes', () => {
27
+ const client = {
28
+ hashString: 'return args.x + 1;',
29
+ hashFn: 'return 2;',
30
+ hashNested: 'return 3;',
31
+ hashUnused: 'return 4;', // present in the map but not referenced by the page
32
+ };
33
+ const pageConfig = {
34
+ id: 'p',
35
+ blocks: [
36
+ { properties: { value: { _js: 'hashString' } } },
37
+ // object form; the args carry another _js node that must be descended into
38
+ { properties: { compute: { _js: { fn: 'hashFn', args: { seed: { _js: 'hashNested' } } } } } },
39
+ // referenced but absent from the client map — excluded, no crash
40
+ { properties: { missing: { _js: 'hashAbsent' } } },
41
+ ],
42
+ };
43
+
44
+ const { jsEntries } = getPageJitEnrichment({
45
+ pageConfig,
46
+ buildContext: buildContext({ client }),
47
+ });
48
+
49
+ expect(jsEntries).toContain("'hashString'");
50
+ expect(jsEntries).toContain("'hashFn'");
51
+ expect(jsEntries).toContain("'hashNested'");
52
+ expect(jsEntries).not.toContain("'hashUnused'");
53
+ expect(jsEntries).not.toContain("'hashAbsent'");
54
+ });
55
+
56
+ test('getPageJitEnrichment discovers an icon name that appears only inside a _js source', () => {
57
+ const client = {
58
+ // The icon name lives only in the function body, in double quotes — the
59
+ // served pageConfig has this replaced by the hash, so scanning the config
60
+ // alone would miss it. Only FiZap is a real dynamic icon.
61
+ hashIcon: 'return on ? "FiZap" : "FiZapOff";',
62
+ };
63
+ const pageConfig = {
64
+ id: 'p',
65
+ blocks: [{ properties: { icon: { _js: 'hashIcon' } } }],
66
+ };
67
+
68
+ const { dynamicIcons } = getPageJitEnrichment({
69
+ pageConfig,
70
+ buildContext: buildContext({ client, dynamicIconData: { FiZap: { tag: 'svg' } } }),
71
+ });
72
+
73
+ expect(dynamicIcons).toEqual({ FiZap: { tag: 'svg' } });
74
+ });
75
+
76
+ test('getPageJitEnrichment scopes icons referenced directly in the page config', () => {
77
+ const pageConfig = { id: 'p', blocks: [{ properties: { icon: 'FiStar' } }] };
78
+
79
+ const { dynamicIcons } = getPageJitEnrichment({
80
+ pageConfig,
81
+ buildContext: buildContext({
82
+ dynamicIconData: { FiStar: { tag: 'svg' }, FiOther: { tag: 'svg' } },
83
+ }),
84
+ });
85
+
86
+ expect(dynamicIcons).toEqual({ FiStar: { tag: 'svg' } });
87
+ });
88
+
89
+ test('getPageJitEnrichment returns {} when there is no build context', () => {
90
+ expect(getPageJitEnrichment({ pageConfig: { id: 'p' }, buildContext: null })).toEqual({});
91
+ });
92
+
93
+ test('getPageJitEnrichment omits both fields when the page has no dynamic _js or icons', () => {
94
+ const pageConfig = { id: 'p', blocks: [{ properties: { title: 'Hello' } }] };
95
+
96
+ const enrichment = getPageJitEnrichment({
97
+ pageConfig,
98
+ buildContext: buildContext({
99
+ client: { hashUnused: 'return 1;' },
100
+ dynamicIconData: { FiZap: {} },
101
+ }),
102
+ });
103
+
104
+ expect(enrichment).toEqual({ jsEntries: undefined, dynamicIcons: undefined });
105
+ });
@@ -16,8 +16,15 @@
16
16
 
17
17
  import fs from 'fs';
18
18
  import path from 'path';
19
- import { serializer } from '@lowdefy/helpers';
20
- import { buildPageJit, createContext, hydrateDeferredRecords, makeId } from '@lowdefy/build/dev';
19
+ import { serializer, type } from '@lowdefy/helpers';
20
+ import {
21
+ buildPageJit,
22
+ createContext,
23
+ generateClientJsModule,
24
+ hydrateDeferredRecords,
25
+ iconPackages,
26
+ makeId,
27
+ } from '@lowdefy/build/dev';
21
28
 
22
29
  import createLogger from './log/createLogger.js';
23
30
  import PageCache from './pageCache.mjs';
@@ -226,4 +233,85 @@ async function buildPageIfNeeded({ pageId, buildDirectory, configDirectory }) {
226
233
  }
227
234
  }
228
235
 
236
+ // Collect every client _js hash the page references. jsMapParser reduces a _js
237
+ // operator to either { _js: "<hash>" } or { _js: { fn: "<hash>", args } }, and
238
+ // keeps args verbatim — so a _js nested inside another's args survives as its
239
+ // own node and must be descended into, or its hash is dropped and the client
240
+ // throws "_js function not found".
241
+ function collectJsHashes(node, hashes) {
242
+ if (type.isArray(node)) {
243
+ for (const item of node) collectJsHashes(item, hashes);
244
+ return;
245
+ }
246
+ if (!type.isObject(node)) return;
247
+ if (Object.prototype.hasOwnProperty.call(node, '_js')) {
248
+ const inner = node._js;
249
+ if (type.isString(inner)) {
250
+ hashes.add(inner);
251
+ return;
252
+ }
253
+ if (type.isObject(inner) && type.isString(inner.fn)) {
254
+ hashes.add(inner.fn);
255
+ collectJsHashes(inner.args, hashes);
256
+ return;
257
+ }
258
+ return;
259
+ }
260
+ for (const value of Object.values(node)) collectJsHashes(value, hashes);
261
+ }
262
+
263
+ // Icons are discovered by detectMissingIcons on the pre-parse page, so a name
264
+ // appearing only inside a _js body is real but is a hash in the served config.
265
+ // Reproduce that surface: scan the served config plus the page's own client _js
266
+ // source strings, and keep only names present in dynamicIconData (which holds
267
+ // only JIT-discovered icons — static ones are already in the client bundle).
268
+ function scopeDynamicIcons({ pageConfig, scopedJsMap, dynamicIconData }) {
269
+ if (Object.keys(dynamicIconData).length === 0) return undefined;
270
+ const scanText = [JSON.stringify(pageConfig), ...Object.values(scopedJsMap)].join('\n');
271
+ const found = {};
272
+ for (const regex of Object.values(iconPackages)) {
273
+ for (const match of scanText.matchAll(regex)) {
274
+ const name = match[1];
275
+ if (dynamicIconData[name] && !found[name]) {
276
+ found[name] = dynamicIconData[name];
277
+ }
278
+ }
279
+ }
280
+ return Object.keys(found).length > 0 ? found : undefined;
281
+ }
282
+
283
+ // Scope this page's JIT-discovered enrichment out of the persistent build
284
+ // context so jitPageHandler can fold it into the page-config response the client
285
+ // already awaits — removing the two secondary fetches that stalled first paint.
286
+ // buildContext defaults to the module-private cachedBuildContext (re-read on
287
+ // every call, so it tracks invalidation resets); tests pass a stub.
288
+ export function getPageJitEnrichment({ pageConfig, buildContext = cachedBuildContext }) {
289
+ // No build context (before the first build, or after an invalidation reset)
290
+ // means nothing JIT-discovered to fold — the page serves what the static
291
+ // client bundle already carries.
292
+ if (!buildContext) return {};
293
+
294
+ const clientJsMap = buildContext.jsMap.client ?? {};
295
+ const hashes = new Set();
296
+ collectJsHashes(pageConfig, hashes);
297
+
298
+ const scopedJsMap = {};
299
+ for (const hash of hashes) {
300
+ if (Object.prototype.hasOwnProperty.call(clientJsMap, hash)) {
301
+ scopedJsMap[hash] = clientJsMap[hash];
302
+ }
303
+ }
304
+
305
+ const jsEntries =
306
+ Object.keys(scopedJsMap).length > 0 ? generateClientJsModule(scopedJsMap) : undefined;
307
+
308
+ const dynamicIcons = scopeDynamicIcons({
309
+ pageConfig,
310
+ scopedJsMap,
311
+ dynamicIconData: buildContext.dynamicIconData ?? {},
312
+ });
313
+
314
+ return { jsEntries, dynamicIcons };
315
+ }
316
+
229
317
  export default buildPageIfNeeded;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-experimental-20260807075508",
3
+ "version": "0.0.0-experimental-20260813120102",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -44,39 +44,39 @@
44
44
  "@hono/mcp": "0.3.0",
45
45
  "@hono/node-server": "2.0.4",
46
46
  "@hono/vite-dev-server": "0.26.0",
47
- "@lowdefy/actions-core": "0.0.0-experimental-20260807075508",
48
- "@lowdefy/api": "0.0.0-experimental-20260807075508",
49
- "@lowdefy/block-utils": "0.0.0-experimental-20260807075508",
50
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260807075508",
51
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260807075508",
52
- "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260807075508",
53
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260807075508",
54
- "@lowdefy/blocks-captcha": "0.0.0-experimental-20260807075508",
55
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260807075508",
56
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260807075508",
57
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260807075508",
58
- "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260807075508",
59
- "@lowdefy/build": "0.0.0-experimental-20260807075508",
60
- "@lowdefy/client": "0.0.0-experimental-20260807075508",
61
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260807075508",
62
- "@lowdefy/connection-mongodb": "0.0.0-experimental-20260807075508",
63
- "@lowdefy/docs-content": "0.0.0-experimental-20260807075508",
64
- "@lowdefy/engine": "0.0.0-experimental-20260807075508",
65
- "@lowdefy/errors": "0.0.0-experimental-20260807075508",
66
- "@lowdefy/helpers": "0.0.0-experimental-20260807075508",
67
- "@lowdefy/layout": "0.0.0-experimental-20260807075508",
68
- "@lowdefy/logger": "0.0.0-experimental-20260807075508",
69
- "@lowdefy/node-utils": "0.0.0-experimental-20260807075508",
70
- "@lowdefy/operators-change-case": "0.0.0-experimental-20260807075508",
71
- "@lowdefy/operators-dayjs": "0.0.0-experimental-20260807075508",
72
- "@lowdefy/operators-diff": "0.0.0-experimental-20260807075508",
73
- "@lowdefy/operators-js": "0.0.0-experimental-20260807075508",
74
- "@lowdefy/operators-mql": "0.0.0-experimental-20260807075508",
75
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260807075508",
76
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260807075508",
77
- "@lowdefy/operators-yaml": "0.0.0-experimental-20260807075508",
78
- "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260807075508",
79
- "@lowdefy/websockets-core": "0.0.0-experimental-20260807075508",
47
+ "@lowdefy/actions-core": "0.0.0-experimental-20260813120102",
48
+ "@lowdefy/api": "0.0.0-experimental-20260813120102",
49
+ "@lowdefy/block-utils": "0.0.0-experimental-20260813120102",
50
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260813120102",
51
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260813120102",
52
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260813120102",
53
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260813120102",
54
+ "@lowdefy/blocks-captcha": "0.0.0-experimental-20260813120102",
55
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20260813120102",
56
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260813120102",
57
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260813120102",
58
+ "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260813120102",
59
+ "@lowdefy/build": "0.0.0-experimental-20260813120102",
60
+ "@lowdefy/client": "0.0.0-experimental-20260813120102",
61
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260813120102",
62
+ "@lowdefy/connection-mongodb": "0.0.0-experimental-20260813120102",
63
+ "@lowdefy/docs-content": "0.0.0-experimental-20260813120102",
64
+ "@lowdefy/engine": "0.0.0-experimental-20260813120102",
65
+ "@lowdefy/errors": "0.0.0-experimental-20260813120102",
66
+ "@lowdefy/helpers": "0.0.0-experimental-20260813120102",
67
+ "@lowdefy/layout": "0.0.0-experimental-20260813120102",
68
+ "@lowdefy/logger": "0.0.0-experimental-20260813120102",
69
+ "@lowdefy/node-utils": "0.0.0-experimental-20260813120102",
70
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20260813120102",
71
+ "@lowdefy/operators-dayjs": "0.0.0-experimental-20260813120102",
72
+ "@lowdefy/operators-diff": "0.0.0-experimental-20260813120102",
73
+ "@lowdefy/operators-js": "0.0.0-experimental-20260813120102",
74
+ "@lowdefy/operators-mql": "0.0.0-experimental-20260813120102",
75
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260813120102",
76
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260813120102",
77
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20260813120102",
78
+ "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260813120102",
79
+ "@lowdefy/websockets-core": "0.0.0-experimental-20260813120102",
80
80
  "@modelcontextprotocol/sdk": "1.29.0",
81
81
  "@tailwindcss/postcss": "4.3.1",
82
82
  "@vitejs/plugin-react": "6.0.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-experimental-20260807075508",
3
+ "version": "0.0.0-experimental-20260813120102",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -50,39 +50,39 @@
50
50
  "@hono/mcp": "0.3.0",
51
51
  "@hono/node-server": "2.0.4",
52
52
  "@hono/vite-dev-server": "0.26.0",
53
- "@lowdefy/actions-core": "0.0.0-experimental-20260807075508",
54
- "@lowdefy/api": "0.0.0-experimental-20260807075508",
55
- "@lowdefy/block-utils": "0.0.0-experimental-20260807075508",
56
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260807075508",
57
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260807075508",
58
- "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260807075508",
59
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260807075508",
60
- "@lowdefy/blocks-captcha": "0.0.0-experimental-20260807075508",
61
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260807075508",
62
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260807075508",
63
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260807075508",
64
- "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260807075508",
65
- "@lowdefy/build": "0.0.0-experimental-20260807075508",
66
- "@lowdefy/client": "0.0.0-experimental-20260807075508",
67
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260807075508",
68
- "@lowdefy/connection-mongodb": "0.0.0-experimental-20260807075508",
69
- "@lowdefy/docs-content": "0.0.0-experimental-20260807075508",
70
- "@lowdefy/engine": "0.0.0-experimental-20260807075508",
71
- "@lowdefy/errors": "0.0.0-experimental-20260807075508",
72
- "@lowdefy/helpers": "0.0.0-experimental-20260807075508",
73
- "@lowdefy/layout": "0.0.0-experimental-20260807075508",
74
- "@lowdefy/logger": "0.0.0-experimental-20260807075508",
75
- "@lowdefy/node-utils": "0.0.0-experimental-20260807075508",
76
- "@lowdefy/operators-change-case": "0.0.0-experimental-20260807075508",
77
- "@lowdefy/operators-dayjs": "0.0.0-experimental-20260807075508",
78
- "@lowdefy/operators-diff": "0.0.0-experimental-20260807075508",
79
- "@lowdefy/operators-js": "0.0.0-experimental-20260807075508",
80
- "@lowdefy/operators-mql": "0.0.0-experimental-20260807075508",
81
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260807075508",
82
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260807075508",
83
- "@lowdefy/operators-yaml": "0.0.0-experimental-20260807075508",
84
- "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260807075508",
85
- "@lowdefy/websockets-core": "0.0.0-experimental-20260807075508",
53
+ "@lowdefy/actions-core": "0.0.0-experimental-20260813120102",
54
+ "@lowdefy/api": "0.0.0-experimental-20260813120102",
55
+ "@lowdefy/block-utils": "0.0.0-experimental-20260813120102",
56
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260813120102",
57
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260813120102",
58
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260813120102",
59
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260813120102",
60
+ "@lowdefy/blocks-captcha": "0.0.0-experimental-20260813120102",
61
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20260813120102",
62
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260813120102",
63
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260813120102",
64
+ "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260813120102",
65
+ "@lowdefy/build": "0.0.0-experimental-20260813120102",
66
+ "@lowdefy/client": "0.0.0-experimental-20260813120102",
67
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260813120102",
68
+ "@lowdefy/connection-mongodb": "0.0.0-experimental-20260813120102",
69
+ "@lowdefy/docs-content": "0.0.0-experimental-20260813120102",
70
+ "@lowdefy/engine": "0.0.0-experimental-20260813120102",
71
+ "@lowdefy/errors": "0.0.0-experimental-20260813120102",
72
+ "@lowdefy/helpers": "0.0.0-experimental-20260813120102",
73
+ "@lowdefy/layout": "0.0.0-experimental-20260813120102",
74
+ "@lowdefy/logger": "0.0.0-experimental-20260813120102",
75
+ "@lowdefy/node-utils": "0.0.0-experimental-20260813120102",
76
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20260813120102",
77
+ "@lowdefy/operators-dayjs": "0.0.0-experimental-20260813120102",
78
+ "@lowdefy/operators-diff": "0.0.0-experimental-20260813120102",
79
+ "@lowdefy/operators-js": "0.0.0-experimental-20260813120102",
80
+ "@lowdefy/operators-mql": "0.0.0-experimental-20260813120102",
81
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260813120102",
82
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260813120102",
83
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20260813120102",
84
+ "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260813120102",
85
+ "@lowdefy/websockets-core": "0.0.0-experimental-20260813120102",
86
86
  "@modelcontextprotocol/sdk": "1.29.0",
87
87
  "@tailwindcss/postcss": "4.3.1",
88
88
  "@vitejs/plugin-react": "6.0.2",
package/src/app.js CHANGED
@@ -57,9 +57,7 @@ import endpointsHandler from './routes/endpoints.js';
57
57
  import getAuth from '../lib/server/auth/getAuth.js';
58
58
  import getStrategies from '../lib/server/auth/getStrategies.js';
59
59
  import getMockUser from '../lib/server/auth/getMockUser.js';
60
- import iconsDynamicHandler from './routes/iconsDynamic.js';
61
60
  import jitPageHandler from './routes/jitPage.js';
62
- import jsEnvHandler from './routes/jsEnv.js';
63
61
  import lowdefyConfig from '../lib/build/config.js';
64
62
  import pingHandler from './routes/ping.js';
65
63
  import reloadHandler from './routes/reload.js';
@@ -80,11 +78,9 @@ function createApp() {
80
78
  const app = basePath ? new Hono().basePath(basePath) : new Hono();
81
79
  const logger = createLogger({ server: 'lowdefy-dev' });
82
80
 
83
- // No api context: SSE/health/static-js routes had no apiWrapper before.
81
+ // No api context: SSE/health routes had no apiWrapper before.
84
82
  app.get('/api/reload', reloadHandler);
85
83
  app.get('/api/ping', pingHandler);
86
- app.get('/api/js/:env', jsEnvHandler);
87
- app.get('/api/icons/dynamic', iconsDynamicHandler);
88
84
  app.get('/api/dev-tools', devToolsHandler);
89
85
  // Annotation helper: the in-page overlay (Cmd/Ctrl+/) POSTs annotation
90
86
  // batches here and gets back the enriched agent-readable text, which the
@@ -17,7 +17,7 @@
17
17
  import { getPageConfig } from '@lowdefy/api';
18
18
 
19
19
  import authJson from '../../lib/build/auth.js';
20
- import buildPageIfNeeded from '../../lib/server/jitPageBuilder.js';
20
+ import buildPageIfNeeded, { getPageJitEnrichment } from '../../lib/server/jitPageBuilder.js';
21
21
  import getPathSegments from '../lib/getPathSegments.js';
22
22
  import lowdefyConfig from '../../lib/build/config.js';
23
23
 
@@ -30,7 +30,7 @@ const basePath = lowdefyConfig.basePath ?? '';
30
30
  // 401 { redirect } — logged-out navigation to a protected page
31
31
  // 403 { redirect } — authorised but second factor not yet enrolled
32
32
  // 404 'Page not found.'
33
- // 200 pageConfig (+ _warnings)
33
+ // 200 pageConfig (+ _warnings, + _jsEntries module text, + _dynamicIcons data)
34
34
  async function jitPageHandler(c) {
35
35
  const context = c.get('lowdefyContext');
36
36
  const pageId = getPathSegments(c, '/api/page/').join('/');
@@ -114,6 +114,12 @@ async function jitPageHandler(c) {
114
114
  if (buildResult?.warnings?.length > 0) {
115
115
  pageConfig._warnings = buildResult.warnings;
116
116
  }
117
+ // Fold this page's JIT-discovered _js entries and dynamic icons into the
118
+ // response the client already awaits, so first paint has everything it needs
119
+ // without the two secondary fetches that stalled in Vite's transform window.
120
+ const { jsEntries, dynamicIcons } = getPageJitEnrichment({ pageConfig });
121
+ if (jsEntries) pageConfig._jsEntries = jsEntries;
122
+ if (dynamicIcons) pageConfig._dynamicIcons = dynamicIcons;
117
123
  return c.json(pageConfig);
118
124
  }
119
125
 
@@ -24,8 +24,10 @@ jest.unstable_mockModule('@lowdefy/api', () => ({
24
24
 
25
25
  // No JIT build work in these tests — the route's build branch is exercised
26
26
  // elsewhere; here we only drive the getPageConfig status fork.
27
+ const mockGetPageJitEnrichment = jest.fn(() => ({}));
27
28
  jest.unstable_mockModule('../../lib/server/jitPageBuilder.js', () => ({
28
29
  default: jest.fn(async () => undefined),
30
+ getPageJitEnrichment: mockGetPageJitEnrichment,
29
31
  }));
30
32
 
31
33
  jest.unstable_mockModule('../../lib/build/auth.js', () => ({
@@ -87,3 +89,19 @@ test('jitPageHandler returns the pageConfig when status is ok', async () => {
87
89
  const body = await res.json();
88
90
  expect(body).toEqual({ id: 'dashboard' });
89
91
  });
92
+
93
+ test('jitPageHandler folds _jsEntries and _dynamicIcons onto the ok response', async () => {
94
+ mockGetPageConfig.mockResolvedValue({ status: 'ok', pageConfig: { id: 'dashboard' } });
95
+ mockGetPageJitEnrichment.mockReturnValueOnce({
96
+ jsEntries: 'export default {};',
97
+ dynamicIcons: { FiZap: { tag: 'svg' } },
98
+ });
99
+ const res = await createApp().request('/api/page/dashboard');
100
+ expect(res.status).toEqual(200);
101
+ const body = await res.json();
102
+ expect(body).toEqual({
103
+ id: 'dashboard',
104
+ _jsEntries: 'export default {};',
105
+ _dynamicIcons: { FiZap: { tag: 'svg' } },
106
+ });
107
+ });
@@ -1,30 +0,0 @@
1
- /*
2
- Copyright 2020-2026 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import fs from 'node:fs';
18
- import path from 'node:path';
19
-
20
- function serveBuildJs(relativePath) {
21
- const filePath = path.join(process.cwd(), 'build', ...relativePath);
22
- try {
23
- return fs.readFileSync(filePath, 'utf8');
24
- } catch {
25
- // Empty default export if the file doesn't exist yet
26
- return 'export default {};';
27
- }
28
- }
29
-
30
- export default serveBuildJs;
@@ -1,25 +0,0 @@
1
- /*
2
- Copyright 2020-2026 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import serveBuildJs from '../lib/serveBuildJs.js';
18
-
19
- function iconsDynamicHandler(c) {
20
- return c.body(serveBuildJs(['plugins', 'iconsDynamic.js']), 200, {
21
- 'Content-Type': 'application/javascript',
22
- });
23
- }
24
-
25
- export default iconsDynamicHandler;
@@ -1,30 +0,0 @@
1
- /*
2
- Copyright 2020-2026 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import serveBuildJs from '../lib/serveBuildJs.js';
18
-
19
- function jsEnvHandler(c) {
20
- const env = c.req.param('env');
21
- if (env !== 'client' && env !== 'server') {
22
- return c.text('Invalid env parameter. Use "client" or "server".', 400);
23
- }
24
- const fileName = env === 'client' ? 'clientJsMap.js' : 'serverJsMap.js';
25
- return c.body(serveBuildJs(['plugins', 'operators', fileName]), 200, {
26
- 'Content-Type': 'application/javascript',
27
- });
28
- }
29
-
30
- export default jsEnvHandler;