dynim-react 1.0.34 → 1.0.36

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.
@@ -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;AAUf,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,IA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AC;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,CAiWlC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
@@ -57,13 +57,13 @@ export function DynimProvider({ children, config = {}, }) {
57
57
  // Theme state (fetched from API per project)
58
58
  const [theme, setTheme] = useState(null);
59
59
  const hasAttemptedThemeLoadRef = useRef(false);
60
- // Keep config callbacks in refs
61
- const configCallbacksRef = useRef({ onError: config.onError });
62
- configCallbacksRef.current = { onError: config.onError };
63
- // Set up shared context for bundles
60
+ // Keep config in ref to avoid re-triggering effects on every render
61
+ const configRef = useRef(config);
62
+ configRef.current = config;
63
+ // Set up shared context for bundles (only once on mount)
64
64
  useEffect(() => {
65
65
  if (!isSharedRegistryReady()) {
66
- const { packages = {}, hooks = {}, contexts = {} } = config;
66
+ const { packages = {}, hooks = {}, contexts = {} } = configRef.current;
67
67
  createSharedContext({
68
68
  React,
69
69
  ReactDOM,
@@ -75,14 +75,14 @@ export function DynimProvider({ children, config = {}, }) {
75
75
  contexts,
76
76
  });
77
77
  }
78
- }, [config]);
78
+ }, []);
79
79
  // Get auth token
80
80
  const getAuthToken = useCallback(async () => {
81
81
  if (cachedTokenRef.current)
82
82
  return cachedTokenRef.current;
83
83
  if (tokenPromiseRef.current)
84
84
  return tokenPromiseRef.current;
85
- const { getSession } = config;
85
+ const { getSession } = configRef.current;
86
86
  if (getSession) {
87
87
  tokenPromiseRef.current = (async () => {
88
88
  try {
@@ -100,24 +100,24 @@ export function DynimProvider({ children, config = {}, }) {
100
100
  return tokenPromiseRef.current;
101
101
  }
102
102
  return null;
103
- }, [config]);
104
- // Initialize code client
103
+ }, []);
104
+ // Initialize code client (only once on mount)
105
105
  useEffect(() => {
106
- const { getSession, onError } = config;
106
+ const { getSession, onError } = configRef.current;
107
107
  codeClientRef.current = createCodeClient({
108
108
  getSession,
109
109
  onMessageUpdate: setCodeMessage,
110
110
  onError: (error) => {
111
111
  console.error('[DynimProvider] Code error:', error);
112
- onError?.(error);
112
+ configRef.current.onError?.(error);
113
113
  },
114
114
  });
115
- }, [config]);
115
+ }, []);
116
116
  // Load bundle ref
117
117
  const loadBundleRef = useRef(null);
118
- // Initialize builder
118
+ // Initialize builder (only once on mount)
119
119
  useEffect(() => {
120
- const { getSession } = config;
120
+ const { getSession } = configRef.current;
121
121
  builderRef.current = createBuilder({
122
122
  getSession,
123
123
  codeClient: codeClientRef.current ?? undefined,
@@ -143,18 +143,18 @@ export function DynimProvider({ children, config = {}, }) {
143
143
  return () => {
144
144
  builderRef.current?.destroy();
145
145
  };
146
- }, [config]);
147
- // Initialize builder client
146
+ }, []);
147
+ // Initialize builder client (only once on mount)
148
148
  useEffect(() => {
149
- const { getSession, onError } = config;
149
+ const { getSession } = configRef.current;
150
150
  builderClientRef.current = createBuilderClient({
151
151
  getSession,
152
152
  onError: (error) => {
153
153
  console.error('[DynimProvider] Error:', error);
154
- onError?.(error);
154
+ configRef.current.onError?.(error);
155
155
  },
156
156
  });
157
- }, [config]);
157
+ }, []);
158
158
  // Get bundle loader
159
159
  const getBundleLoader = useCallback(() => {
160
160
  if (!bundleLoaderRef.current) {
@@ -163,7 +163,7 @@ export function DynimProvider({ children, config = {}, }) {
163
163
  includeCredentials: true,
164
164
  onError: (error) => {
165
165
  console.error('[DynimProvider] Bundle load failed:', error);
166
- configCallbacksRef.current.onError?.(error);
166
+ configRef.current.onError?.(error);
167
167
  },
168
168
  });
169
169
  }
@@ -198,74 +198,43 @@ export function DynimProvider({ children, config = {}, }) {
198
198
  useEffect(() => {
199
199
  loadBundleRef.current = loadBundle;
200
200
  }, [loadBundle]);
201
- // Prefetch auth token
202
- useEffect(() => {
203
- if (config.getSession) {
204
- getAuthToken();
205
- }
206
- }, []);
207
- // Fetch theme from API (per project)
208
- useEffect(() => {
201
+ // Theme is fetched lazily when entering builder mode
202
+ // This avoids making HTTP requests on mount that could trigger auth redirects
203
+ const fetchTheme = useCallback(async () => {
209
204
  if (hasAttemptedThemeLoadRef.current)
210
205
  return;
211
- if (!config.getSession)
206
+ if (!configRef.current.getSession)
212
207
  return;
213
208
  hasAttemptedThemeLoadRef.current = true;
214
- const fetchTheme = async () => {
215
- try {
216
- const token = await getAuthToken();
217
- const headers = {};
218
- if (token) {
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
- }
209
+ try {
210
+ const token = await getAuthToken();
211
+ const headers = {};
212
+ if (token) {
213
+ headers['Authorization'] = `Bearer ${token}`;
229
214
  }
230
- catch (error) {
231
- // Theme fetch failed - use defaults (non-critical)
232
- console.warn('[DynimProvider] Failed to fetch theme:', error);
215
+ const response = await fetch('/api/code/theme', {
216
+ headers,
217
+ credentials: 'include',
218
+ });
219
+ if (response.ok) {
220
+ const data = await response.json();
221
+ setTheme(data);
233
222
  }
234
- };
235
- fetchTheme();
236
- }, [config.getSession, getAuthToken]);
237
- // Auto-load bundle on mount (only if we can get a valid auth token)
223
+ }
224
+ catch (error) {
225
+ // Theme fetch failed - use defaults (non-critical)
226
+ console.warn('[DynimProvider] Failed to fetch theme:', error);
227
+ }
228
+ }, [getAuthToken]);
229
+ // Mark initial load complete immediately - no eager HTTP requests
230
+ // Bundle loading happens lazily when user enters builder or when
231
+ // the consuming app explicitly triggers it
238
232
  useEffect(() => {
239
- if (hasAttemptedInitialLoadRef.current)
240
- return;
241
- if (!config.getSession) {
233
+ if (!hasAttemptedInitialLoadRef.current) {
234
+ hasAttemptedInitialLoadRef.current = true;
242
235
  setIsInitialLoadComplete(true);
243
- return;
244
236
  }
245
- hasAttemptedInitialLoadRef.current = true;
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
- }, [config.getSession, getAuthToken]);
237
+ }, []);
269
238
  // Load saved bundle
270
239
  const loadSavedBundle = useCallback(async () => {
271
240
  await loadBundle('/api/code/bundle');
@@ -296,8 +265,10 @@ export function DynimProvider({ children, config = {}, }) {
296
265
  const enterBuilder = useCallback(() => {
297
266
  if (builderRef.current && !builderRef.current.isActive()) {
298
267
  builderRef.current.enter();
268
+ // Fetch theme lazily when entering builder
269
+ fetchTheme();
299
270
  }
300
- }, []);
271
+ }, [fetchTheme]);
301
272
  const exitBuilder = useCallback(() => {
302
273
  if (builderRef.current && builderRef.current.isActive()) {
303
274
  builderRef.current.exit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynim-react",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",