@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.js CHANGED
@@ -269,6 +269,18 @@ function MaybeWrap(props) {
269
269
  function uniq(elements) {
270
270
  return Array.from(new Set(elements));
271
271
  }
272
+ function uniqBy(elements, iterator) {
273
+ const vis = /* @__PURE__ */ new Set();
274
+ const filtered = [];
275
+ for (const elt of elements) {
276
+ const key = iterator(elt);
277
+ if (!vis.has(key)) {
278
+ vis.add(key);
279
+ filtered.push(elt);
280
+ }
281
+ }
282
+ return filtered;
283
+ }
272
284
 
273
285
  // src/variation.ts
274
286
  function getPlasmicCookieValues() {
@@ -352,7 +364,7 @@ function PlasmicRootProvider(props) {
352
364
  } = props;
353
365
  const loader = props.loader.__internal;
354
366
  if (prefetchedData) {
355
- loader.registerPrefetchedBundle(prefetchedData == null ? void 0 : prefetchedData.bundle);
367
+ loader.registerPrefetchedBundle(prefetchedData.bundle);
356
368
  }
357
369
  const [splits, setSplits] = React2.useState(loader.getActiveSplits());
358
370
  const forceUpdate = useForceUpdate();
@@ -369,6 +381,66 @@ function PlasmicRootProvider(props) {
369
381
  loader.subscribePlasmicRoot(watcher);
370
382
  return () => loader.unsubscribePlasmicRoot(watcher);
371
383
  }, [watcher, loader]);
384
+ const currentContextValue = React2.useContext(PlasmicRootContext);
385
+ const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
386
+ const value = React2.useMemo(() => {
387
+ var _a, _b, _c;
388
+ const withCurrentContextValueFallback = (v, key) => {
389
+ return v !== void 0 ? v : currentContextValue == null ? void 0 : currentContextValue[key];
390
+ };
391
+ return {
392
+ globalVariants: [
393
+ ...mergeGlobalVariantsSpec(
394
+ globalVariants != null ? globalVariants : [],
395
+ getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
396
+ ),
397
+ ...(_a = currentContextValue == null ? void 0 : currentContextValue.globalVariants) != null ? _a : []
398
+ ],
399
+ globalContextsProps: __spreadValues(__spreadValues({}, (_b = currentContextValue == null ? void 0 : currentContextValue.globalContextsProps) != null ? _b : {}), globalContextsProps != null ? globalContextsProps : {}),
400
+ loader: withCurrentContextValueFallback(loader, "loader"),
401
+ variation: __spreadValues(__spreadValues({}, (_c = currentContextValue == null ? void 0 : currentContextValue.variation) != null ? _c : {}), variation != null ? variation : {}),
402
+ translator: withCurrentContextValueFallback(translator, "translator"),
403
+ Head: withCurrentContextValueFallback(Head, "Head"),
404
+ Link: withCurrentContextValueFallback(Link, "Link"),
405
+ user: withCurrentContextValueFallback(user, "user"),
406
+ userAuthToken: withCurrentContextValueFallback(
407
+ userAuthToken,
408
+ "userAuthToken"
409
+ ),
410
+ isUserLoading: withCurrentContextValueFallback(
411
+ isUserLoading,
412
+ "isUserLoading"
413
+ ),
414
+ authRedirectUri: withCurrentContextValueFallback(
415
+ authRedirectUri,
416
+ "authRedirectUri"
417
+ ),
418
+ suspenseFallback: withCurrentContextValueFallback(
419
+ suspenseFallback,
420
+ "suspenseFallback"
421
+ ),
422
+ disableLoadingBoundary: withCurrentContextValueFallback(
423
+ disableLoadingBoundary,
424
+ "disableLoadingBoundary"
425
+ )
426
+ };
427
+ }, [
428
+ globalVariants,
429
+ variation,
430
+ globalContextsProps,
431
+ loader,
432
+ splits,
433
+ translator,
434
+ Head,
435
+ Link,
436
+ user,
437
+ userAuthToken,
438
+ isUserLoading,
439
+ authRedirectUri,
440
+ suspenseFallback,
441
+ disableLoadingBoundary,
442
+ currentContextValue
443
+ ]);
372
444
  React2.useEffect(() => {
373
445
  ensureVariationCookies(variation);
374
446
  loader.trackRender({
@@ -378,46 +450,9 @@ function PlasmicRootProvider(props) {
378
450
  teamIds: loader.getTeamIds(),
379
451
  projectIds: loader.getProjectIds()
380
452
  },
381
- variation
453
+ variation: value.variation
382
454
  });
383
- }, [loader, variation]);
384
- const { user, userAuthToken, isUserLoading, authRedirectUri } = props;
385
- const value = React2.useMemo(
386
- () => ({
387
- globalVariants: mergeGlobalVariantsSpec(
388
- globalVariants != null ? globalVariants : [],
389
- getGlobalVariantsFromSplits(splits, variation != null ? variation : {})
390
- ),
391
- globalContextsProps,
392
- loader,
393
- variation,
394
- translator,
395
- Head,
396
- Link,
397
- user,
398
- userAuthToken,
399
- isUserLoading,
400
- authRedirectUri,
401
- suspenseFallback,
402
- disableLoadingBoundary
403
- }),
404
- [
405
- globalVariants,
406
- variation,
407
- globalContextsProps,
408
- loader,
409
- splits,
410
- translator,
411
- Head,
412
- Link,
413
- user,
414
- userAuthToken,
415
- isUserLoading,
416
- authRedirectUri,
417
- suspenseFallback,
418
- disableLoadingBoundary
419
- ]
420
- );
455
+ }, [loader, value]);
421
456
  const reactMajorVersion = +React2.version.split(".")[0];
422
457
  return /* @__PURE__ */ React2.createElement(
423
458
  import_query.PlasmicQueryDataProvider,
@@ -631,11 +666,6 @@ function mergeBundles(target, from) {
631
666
  globalGroups: [...target.globalGroups, ...newGlobals]
632
667
  });
633
668
  }
634
- const existingExternals = new Set(target.external);
635
- const newExternals = target.external.filter((x) => !existingExternals.has(x));
636
- if (newExternals.length > 0) {
637
- target = __spreadProps(__spreadValues({}, target), { external: [...target.external, ...newExternals] });
638
- }
639
669
  const existingSplitIds = new Set(target.activeSplits.map((s) => s.id));
640
670
  const newSplits = (_a = from.activeSplits.filter((s) => !existingSplitIds.has(s.id))) != null ? _a : [];
641
671
  if (newSplits.length > 0) {
@@ -755,7 +785,6 @@ var BaseInternalPlasmicComponentLoader = class {
755
785
  },
756
786
  components: [],
757
787
  globalGroups: [],
758
- external: [],
759
788
  projects: [],
760
789
  activeSplits: [],
761
790
  bundleKey: null,
@@ -869,11 +898,50 @@ var BaseInternalPlasmicComponentLoader = class {
869
898
  return bundle;
870
899
  });
871
900
  }
872
- mergeBundle(bundle) {
873
- var _a, _b;
874
- this.bundle = bundle;
875
- this.bundle.bundleKey = (_a = this.bundle.bundleKey) != null ? _a : null;
876
- (_b = this.onBundleMerged) == null ? void 0 : _b.call(this);
901
+ mergeBundle(newBundle) {
902
+ var _a, _b, _c, _d, _e;
903
+ newBundle.bundleKey = (_a = newBundle.bundleKey) != null ? _a : null;
904
+ if (newBundle.bundleKey && this.bundle.bundleKey && newBundle.bundleKey !== this.bundle.bundleKey) {
905
+ console.warn(
906
+ `Plasmic Error: Different code export hashes. This can happen if your app is using different loaders with different project IDs or project versions.
907
+ Conflicting values:
908
+ ${newBundle.bundleKey}
909
+ ${this.bundle.bundleKey}`
910
+ );
911
+ }
912
+ const bundles = [this.bundle, newBundle];
913
+ this.bundle = {
914
+ activeSplits: uniqBy(
915
+ bundles.flatMap((bundle) => bundle.activeSplits),
916
+ (split) => split.id
917
+ ),
918
+ components: uniqBy(
919
+ bundles.flatMap((bundle) => bundle.components),
920
+ (c) => c.id
921
+ ),
922
+ globalGroups: uniqBy(
923
+ bundles.flatMap((bundle) => bundle.globalGroups),
924
+ (g) => g.id
925
+ ),
926
+ modules: {
927
+ browser: uniqBy(
928
+ bundles.flatMap((bundle) => bundle.modules.browser),
929
+ (m) => m.fileName
930
+ ),
931
+ server: uniqBy(
932
+ bundles.flatMap((bundle) => bundle.modules.server),
933
+ (m) => m.fileName
934
+ )
935
+ },
936
+ projects: uniqBy(
937
+ bundles.flatMap((bundle) => bundle.projects),
938
+ (p) => p.id
939
+ ),
940
+ // Avoid `undefined` as it cannot be serialized as JSON
941
+ bundleKey: (_c = (_b = newBundle.bundleKey) != null ? _b : this.bundle.bundleKey) != null ? _c : null,
942
+ deferChunksByDefault: (_d = newBundle.deferChunksByDefault) != null ? _d : false
943
+ };
944
+ (_e = this.onBundleMerged) == null ? void 0 : _e.call(this);
877
945
  }
878
946
  getBundle() {
879
947
  return this.bundle;
@@ -886,7 +954,6 @@ var BaseInternalPlasmicComponentLoader = class {
886
954
  },
887
955
  components: [],
888
956
  globalGroups: [],
889
- external: [],
890
957
  projects: [],
891
958
  activeSplits: [],
892
959
  bundleKey: null,