dynim-react 1.0.35 → 1.0.37
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/DynimProvider.d.ts.map +1 -1
- package/dist/DynimProvider.js +47 -66
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AASf,OAAO,KAAK,EAKV,WAAW,EAEZ,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,KAAK,IAAI,CAAC;IACzC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,qBAAqB;IACrB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,0CAA0C;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,yBAAyB;IACzB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,oCAAoC;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,yDAAyD;IACzD,WAAW,EAAE,WAAW,CAAC;IACzB,2CAA2C;IAC3C,cAAc,EAAE,OAAO,CAAC;IACxB,gCAAgC;IAChC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,MAAW,GACZ,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CA0WlC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
|
package/dist/DynimProvider.js
CHANGED
|
@@ -9,8 +9,8 @@ import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-run
|
|
|
9
9
|
*/
|
|
10
10
|
import React, { createContext, useContext, useEffect, useRef, useCallback, useMemo, useState, } from 'react';
|
|
11
11
|
import ReactDOM from 'react-dom';
|
|
12
|
-
import { createBuilderClient, createBuilder, createCodeClient, createBundleLoader, BundleNotFoundError,
|
|
13
|
-
import { createSharedContext } from './inference/sharedContext';
|
|
12
|
+
import { createBuilderClient, createBuilder, createCodeClient, createBundleLoader, BundleNotFoundError, } from 'dynim-core';
|
|
13
|
+
import { createSharedContext, updateSharedContext, isSharedContextReady } from './inference/sharedContext';
|
|
14
14
|
import { generateThemeCSS } from './theme';
|
|
15
15
|
const DynimContext = createContext(null);
|
|
16
16
|
/**
|
|
@@ -62,15 +62,25 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
62
62
|
configRef.current = config;
|
|
63
63
|
// Set up shared context for bundles (only once on mount)
|
|
64
64
|
useEffect(() => {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const { packages = {}, hooks = {}, contexts = {} } = configRef.current;
|
|
66
|
+
const sdkPackages = {
|
|
67
|
+
'dynim-react': { DynimProvider, useDynim },
|
|
68
|
+
...packages,
|
|
69
|
+
};
|
|
70
|
+
if (!isSharedContextReady()) {
|
|
71
|
+
// Create fresh shared context
|
|
67
72
|
createSharedContext({
|
|
68
73
|
React,
|
|
69
74
|
ReactDOM,
|
|
70
|
-
packages:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
packages: sdkPackages,
|
|
76
|
+
hooks,
|
|
77
|
+
contexts,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Update existing context with packages (handles HMR)
|
|
82
|
+
updateSharedContext({
|
|
83
|
+
packages: sdkPackages,
|
|
74
84
|
hooks,
|
|
75
85
|
contexts,
|
|
76
86
|
});
|
|
@@ -198,74 +208,43 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
198
208
|
useEffect(() => {
|
|
199
209
|
loadBundleRef.current = loadBundle;
|
|
200
210
|
}, [loadBundle]);
|
|
201
|
-
//
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
getAuthToken();
|
|
205
|
-
}
|
|
206
|
-
}, [getAuthToken]);
|
|
207
|
-
// Fetch theme from API (per project, only once)
|
|
208
|
-
useEffect(() => {
|
|
211
|
+
// Theme is fetched lazily when entering builder mode
|
|
212
|
+
// This avoids making HTTP requests on mount that could trigger auth redirects
|
|
213
|
+
const fetchTheme = useCallback(async () => {
|
|
209
214
|
if (hasAttemptedThemeLoadRef.current)
|
|
210
215
|
return;
|
|
211
216
|
if (!configRef.current.getSession)
|
|
212
217
|
return;
|
|
213
218
|
hasAttemptedThemeLoadRef.current = true;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
220
|
-
}
|
|
221
|
-
const response = await fetch('/api/code/theme', {
|
|
222
|
-
headers,
|
|
223
|
-
credentials: 'include',
|
|
224
|
-
});
|
|
225
|
-
if (response.ok) {
|
|
226
|
-
const data = await response.json();
|
|
227
|
-
setTheme(data);
|
|
228
|
-
}
|
|
219
|
+
try {
|
|
220
|
+
const token = await getAuthToken();
|
|
221
|
+
const headers = {};
|
|
222
|
+
if (token) {
|
|
223
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
229
224
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
const response = await fetch('/api/code/theme', {
|
|
226
|
+
headers,
|
|
227
|
+
credentials: 'include',
|
|
228
|
+
});
|
|
229
|
+
if (response.ok) {
|
|
230
|
+
const data = await response.json();
|
|
231
|
+
setTheme(data);
|
|
233
232
|
}
|
|
234
|
-
}
|
|
235
|
-
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
// Theme fetch failed - use defaults (non-critical)
|
|
236
|
+
console.warn('[DynimProvider] Failed to fetch theme:', error);
|
|
237
|
+
}
|
|
236
238
|
}, [getAuthToken]);
|
|
237
|
-
//
|
|
239
|
+
// Mark initial load complete immediately - no eager HTTP requests
|
|
240
|
+
// Bundle loading happens lazily when user enters builder or when
|
|
241
|
+
// the consuming app explicitly triggers it
|
|
238
242
|
useEffect(() => {
|
|
239
|
-
if (hasAttemptedInitialLoadRef.current)
|
|
240
|
-
|
|
241
|
-
if (!configRef.current.getSession) {
|
|
243
|
+
if (!hasAttemptedInitialLoadRef.current) {
|
|
244
|
+
hasAttemptedInitialLoadRef.current = true;
|
|
242
245
|
setIsInitialLoadComplete(true);
|
|
243
|
-
return;
|
|
244
246
|
}
|
|
245
|
-
|
|
246
|
-
const doInitialLoad = async () => {
|
|
247
|
-
// First check if we can get a valid auth token
|
|
248
|
-
const token = await getAuthToken();
|
|
249
|
-
if (!token) {
|
|
250
|
-
// No auth token = user not logged in, skip bundle load
|
|
251
|
-
setIsInitialLoadComplete(true);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
const bundleUrl = '/api/code/bundle';
|
|
255
|
-
if (loadBundleRef.current) {
|
|
256
|
-
try {
|
|
257
|
-
await loadBundleRef.current(bundleUrl);
|
|
258
|
-
}
|
|
259
|
-
finally {
|
|
260
|
-
setIsInitialLoadComplete(true);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
setIsInitialLoadComplete(true);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
doInitialLoad();
|
|
268
|
-
}, [getAuthToken]);
|
|
247
|
+
}, []);
|
|
269
248
|
// Load saved bundle
|
|
270
249
|
const loadSavedBundle = useCallback(async () => {
|
|
271
250
|
await loadBundle('/api/code/bundle');
|
|
@@ -296,8 +275,10 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
296
275
|
const enterBuilder = useCallback(() => {
|
|
297
276
|
if (builderRef.current && !builderRef.current.isActive()) {
|
|
298
277
|
builderRef.current.enter();
|
|
278
|
+
// Fetch theme lazily when entering builder
|
|
279
|
+
fetchTheme();
|
|
299
280
|
}
|
|
300
|
-
}, []);
|
|
281
|
+
}, [fetchTheme]);
|
|
301
282
|
const exitBuilder = useCallback(() => {
|
|
302
283
|
if (builderRef.current && builderRef.current.isActive()) {
|
|
303
284
|
builderRef.current.exit();
|