@plasmicapp/loader-react 1.0.342 → 1.0.343

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/index.d.ts CHANGED
@@ -84,7 +84,7 @@ declare abstract class BaseInternalPlasmicComponentLoader {
84
84
  private fetchMissingData;
85
85
  private maybeReportClientSideFetch;
86
86
  private fetchAllData;
87
- mergeBundle(bundle: LoaderBundleOutput): void;
87
+ mergeBundle(newBundle: LoaderBundleOutput): void;
88
88
  getBundle(): LoaderBundleOutput;
89
89
  clearCache(): void;
90
90
  registerModules(modules: Record<string, any>): void;
package/dist/index.esm.js CHANGED
@@ -217,6 +217,18 @@ function MaybeWrap(props) {
217
217
  function uniq(elements) {
218
218
  return Array.from(new Set(elements));
219
219
  }
220
+ function uniqBy(elements, iterator) {
221
+ const vis = /* @__PURE__ */ new Set();
222
+ const filtered = [];
223
+ for (const elt of elements) {
224
+ const key = iterator(elt);
225
+ if (!vis.has(key)) {
226
+ vis.add(key);
227
+ filtered.push(elt);
228
+ }
229
+ }
230
+ return filtered;
231
+ }
220
232
 
221
233
  // src/variation.ts
222
234
  function getPlasmicCookieValues() {
@@ -300,7 +312,7 @@ function PlasmicRootProvider(props) {
300
312
  } = props;
301
313
  const loader = props.loader.__internal;
302
314
  if (prefetchedData) {
303
- loader.registerPrefetchedBundle(prefetchedData == null ? void 0 : prefetchedData.bundle);
315
+ loader.registerPrefetchedBundle(prefetchedData.bundle);
304
316
  }
305
317
  const [splits, setSplits] = React2.useState(loader.getActiveSplits());
306
318
  const forceUpdate = useForceUpdate();
@@ -317,6 +329,66 @@ function PlasmicRootProvider(props) {
317
329
  loader.subscribePlasmicRoot(watcher);
318
330
  return () => loader.unsubscribePlasmicRoot(watcher);
319
331
  }, [watcher, loader]);
332
+ const currentContextValue = React2.useContext(PlasmicRootContext);
333
+ const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
334
+ const value = React2.useMemo(() => {
335
+ var _a, _b, _c;
336
+ const withCurrentContextValueFallback = (v, key) => {
337
+ return v !== void 0 ? v : currentContextValue == null ? void 0 : currentContextValue[key];
338
+ };
339
+ return {
340
+ globalVariants: [
341
+ ...mergeGlobalVariantsSpec(
342
+ globalVariants != null ? globalVariants : [],
343
+ getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
344
+ ),
345
+ ...(_a = currentContextValue == null ? void 0 : currentContextValue.globalVariants) != null ? _a : []
346
+ ],
347
+ globalContextsProps: __spreadValues(__spreadValues({}, (_b = currentContextValue == null ? void 0 : currentContextValue.globalContextsProps) != null ? _b : {}), globalContextsProps != null ? globalContextsProps : {}),
348
+ loader: withCurrentContextValueFallback(loader, "loader"),
349
+ variation: __spreadValues(__spreadValues({}, (_c = currentContextValue == null ? void 0 : currentContextValue.variation) != null ? _c : {}), variation != null ? variation : {}),
350
+ translator: withCurrentContextValueFallback(translator, "translator"),
351
+ Head: withCurrentContextValueFallback(Head, "Head"),
352
+ Link: withCurrentContextValueFallback(Link, "Link"),
353
+ user: withCurrentContextValueFallback(user, "user"),
354
+ userAuthToken: withCurrentContextValueFallback(
355
+ userAuthToken,
356
+ "userAuthToken"
357
+ ),
358
+ isUserLoading: withCurrentContextValueFallback(
359
+ isUserLoading,
360
+ "isUserLoading"
361
+ ),
362
+ authRedirectUri: withCurrentContextValueFallback(
363
+ authRedirectUri,
364
+ "authRedirectUri"
365
+ ),
366
+ suspenseFallback: withCurrentContextValueFallback(
367
+ suspenseFallback,
368
+ "suspenseFallback"
369
+ ),
370
+ disableLoadingBoundary: withCurrentContextValueFallback(
371
+ disableLoadingBoundary,
372
+ "disableLoadingBoundary"
373
+ )
374
+ };
375
+ }, [
376
+ globalVariants,
377
+ variation,
378
+ globalContextsProps,
379
+ loader,
380
+ splits,
381
+ translator,
382
+ Head,
383
+ Link,
384
+ user,
385
+ userAuthToken,
386
+ isUserLoading,
387
+ authRedirectUri,
388
+ suspenseFallback,
389
+ disableLoadingBoundary,
390
+ currentContextValue
391
+ ]);
320
392
  React2.useEffect(() => {
321
393
  ensureVariationCookies(variation);
322
394
  loader.trackRender({
@@ -326,46 +398,9 @@ function PlasmicRootProvider(props) {
326
398
  teamIds: loader.getTeamIds(),
327
399
  projectIds: loader.getProjectIds()
328
400
  },
329
- variation
401
+ variation: value.variation
330
402
  });
331
- }, [loader, variation]);
332
- const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
333
- const value = React2.useMemo(
334
- () => ({
335
- globalVariants: mergeGlobalVariantsSpec(
336
- globalVariants != null ? globalVariants : [],
337
- getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
338
- ),
339
- globalContextsProps,
340
- loader,
341
- variation,
342
- translator,
343
- Head,
344
- Link,
345
- user,
346
- userAuthToken,
347
- isUserLoading,
348
- authRedirectUri,
349
- suspenseFallback,
350
- disableLoadingBoundary
351
- }),
352
- [
353
- globalVariants,
354
- variation,
355
- globalContextsProps,
356
- loader,
357
- splits,
358
- translator,
359
- Head,
360
- Link,
361
- user,
362
- userAuthToken,
363
- isUserLoading,
364
- authRedirectUri,
365
- suspenseFallback,
366
- disableLoadingBoundary
367
- ]
368
- );
403
+ }, [loader, value]);
369
404
  const reactMajorVersion = +React2.version.split(".")[0];
370
405
  return /* @__PURE__ */ React2.createElement(
371
406
  PlasmicQueryDataProvider,
@@ -585,11 +620,6 @@ function mergeBundles(target, from) {
585
620
  globalGroups: [...target.globalGroups, ...newGlobals]
586
621
  });
587
622
  }
588
- const existingExternals = new Set(target.external);
589
- const newExternals = target.external.filter((x) => !existingExternals.has(x));
590
- if (newExternals.length > 0) {
591
- target = __spreadProps(__spreadValues({}, target), { external: [...target.external, ...newExternals] });
592
- }
593
623
  const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
594
624
  const newSplits = (_a = from.activeSplits.filter((s) => !existingSplitIds.has(s.id))) != null ? _a : [];
595
625
  if (newSplits.length > 0) {
@@ -709,7 +739,6 @@ var BaseInternalPlasmicComponentLoader = class {
709
739
  },
710
740
  components: [],
711
741
  globalGroups: [],
712
- external: [],
713
742
  projects: [],
714
743
  activeSplits: [],
715
744
  bundleKey: null,
@@ -823,11 +852,50 @@ var BaseInternalPlasmicComponentLoader = class {
823
852
  return bundle;
824
853
  });
825
854
  }
826
- mergeBundle(bundle) {
827
- var _a, _b;
828
- this.bundle = bundle;
829
- this.bundle.bundleKey = (_a = this.bundle.bundleKey) != null ? _a : null;
830
- (_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
855
+ mergeBundle(newBundle) {
856
+ var _a, _b, _c, _d, _e;
857
+ newBundle.bundleKey = (_a = newBundle.bundleKey) != null ? _a : null;
858
+ if (newBundle.bundleKey && this.bundle.bundleKey && newBundle.bundleKey !== this.bundle.bundleKey) {
859
+ console.warn(
860
+ `Plasmic Error: Different code export hashes. This can happen if your app is using different loaders with different project IDs or project versions.
861
+ Conflicting values:
862
+ ${newBundle.bundleKey}
863
+ ${this.bundle.bundleKey}`
864
+ );
865
+ }
866
+ const bundles = [this.bundle, newBundle];
867
+ this.bundle = {
868
+ activeSplits: uniqBy(
869
+ bundles.flatMap((bundle) => bundle.activeSplits),
870
+ (split) => split.id
871
+ ),
872
+ components: uniqBy(
873
+ bundles.flatMap((bundle) => bundle.components),
874
+ (c) => c.id
875
+ ),
876
+ globalGroups: uniqBy(
877
+ bundles.flatMap((bundle) => bundle.globalGroups),
878
+ (g) => g.id
879
+ ),
880
+ modules: {
881
+ browser: uniqBy(
882
+ bundles.flatMap((bundle) => bundle.modules.browser),
883
+ (m) => m.fileName
884
+ ),
885
+ server: uniqBy(
886
+ bundles.flatMap((bundle) => bundle.modules.server),
887
+ (m) => m.fileName
888
+ )
889
+ },
890
+ projects: uniqBy(
891
+ bundles.flatMap((bundle) => bundle.projects),
892
+ (p) => p.id
893
+ ),
894
+ // Avoid `undefined` as it cannot be serialized as JSON
895
+ bundleKey: (_c = (_b = newBundle.bundleKey) != null ? _b : this.bundle.bundleKey) != null ? _c : null,
896
+ deferChunksByDefault: (_d = newBundle.deferChunksByDefault) != null ? _d : false
897
+ };
898
+ (_e = this.onBundleMerged) == null ? void 0 : _e.call(this);
831
899
  }
832
900
  getBundle() {
833
901
  return this.bundle;
@@ -840,7 +908,6 @@ var BaseInternalPlasmicComponentLoader = class {
840
908
  },
841
909
  components: [],
842
910
  globalGroups: [],
843
- external: [],
844
911
  projects: [],
845
912
  activeSplits: [],
846
913
  bundleKey: null,