@uniformdev/next-app-router 20.50.0 → 20.50.1-alpha.16

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.esm.js CHANGED
@@ -2749,6 +2749,13 @@ var createTestComponentProps = ({
2749
2749
  test
2750
2750
  }) => {
2751
2751
  var _a;
2752
+ if (pageState.isPrefetch) {
2753
+ return {
2754
+ ...common,
2755
+ index: void 0,
2756
+ test
2757
+ };
2758
+ }
2752
2759
  const component = resolveComponentFromPageState({
2753
2760
  pageState,
2754
2761
  componentId
@@ -2787,6 +2794,7 @@ var applyEditableParameters = ({
2787
2794
  };
2788
2795
 
2789
2796
  // src/components/Test.tsx
2797
+ import { ClientTest } from "@uniformdev/next-app-router-client";
2790
2798
  import { createElement, Fragment } from "react";
2791
2799
 
2792
2800
  // src/components/ContextTestTransfer.tsx
@@ -2799,7 +2807,14 @@ var ContextTestTransfer = ({ event }) => {
2799
2807
  // src/components/Test.tsx
2800
2808
  var Test = ({ index, slots, test, component, context: compositionContext }) => {
2801
2809
  var _a, _b, _c, _d, _e, _f;
2802
- const indexToShow = typeof index === "number" ? (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null : null;
2810
+ if (typeof index !== "number") {
2811
+ return createElement(ClientTest, {
2812
+ slots,
2813
+ test,
2814
+ context: compositionContext
2815
+ });
2816
+ }
2817
+ const indexToShow = (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null;
2803
2818
  const event = {
2804
2819
  name: test.name,
2805
2820
  control: (_d = (_c = test.variations[index]) == null ? void 0 : _c.control) != null ? _d : false,
@@ -3580,7 +3595,8 @@ var generatePossiblePageStates = ({
3580
3595
  defaultConsent: void 0,
3581
3596
  previewMode: void 0,
3582
3597
  rules: void 0,
3583
- locale
3598
+ locale,
3599
+ isPrefetch: void 0
3584
3600
  };
3585
3601
  const allStates = generateStatesRecursively(dependencyMap, void 0, initialState);
3586
3602
  return allStates.map((payload) => serializeEvaluationResult({ payload }));
package/dist/index.js CHANGED
@@ -2678,7 +2678,7 @@ var getRouteClient = (options) => {
2678
2678
 
2679
2679
  // src/components/UniformComposition.tsx
2680
2680
  var import_core = require("@uniformdev/canvas-react/core");
2681
- var import_next_app_router_client4 = require("@uniformdev/next-app-router-client");
2681
+ var import_next_app_router_client5 = require("@uniformdev/next-app-router-client");
2682
2682
  var import_next_app_router_shared4 = require("@uniformdev/next-app-router-shared");
2683
2683
  var import_navigation = require("next/navigation");
2684
2684
  var import_react6 = __toESM(require("react"));
@@ -2772,6 +2772,13 @@ var createTestComponentProps = ({
2772
2772
  test
2773
2773
  }) => {
2774
2774
  var _a;
2775
+ if (pageState.isPrefetch) {
2776
+ return {
2777
+ ...common,
2778
+ index: void 0,
2779
+ test
2780
+ };
2781
+ }
2775
2782
  const component = (0, import_next_app_router_shared2.resolveComponentFromPageState)({
2776
2783
  pageState,
2777
2784
  componentId
@@ -2810,6 +2817,7 @@ var applyEditableParameters = ({
2810
2817
  };
2811
2818
 
2812
2819
  // src/components/Test.tsx
2820
+ var import_next_app_router_client2 = require("@uniformdev/next-app-router-client");
2813
2821
  var import_react2 = require("react");
2814
2822
 
2815
2823
  // src/components/ContextTestTransfer.tsx
@@ -2822,7 +2830,14 @@ var ContextTestTransfer = ({ event }) => {
2822
2830
  // src/components/Test.tsx
2823
2831
  var Test = ({ index, slots, test, component, context: compositionContext }) => {
2824
2832
  var _a, _b, _c, _d, _e, _f;
2825
- const indexToShow = typeof index === "number" ? (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null : null;
2833
+ if (typeof index !== "number") {
2834
+ return (0, import_react2.createElement)(import_next_app_router_client2.ClientTest, {
2835
+ slots,
2836
+ test,
2837
+ context: compositionContext
2838
+ });
2839
+ }
2840
+ const indexToShow = (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null;
2826
2841
  const event = {
2827
2842
  name: test.name,
2828
2843
  control: (_d = (_c = test.variations[index]) == null ? void 0 : _c.control) != null ? _d : false,
@@ -2854,7 +2869,7 @@ var UniformCompositionWrapper = ({
2854
2869
  };
2855
2870
 
2856
2871
  // src/components/UniformContext.tsx
2857
- var import_next_app_router_client2 = require("@uniformdev/next-app-router-client");
2872
+ var import_next_app_router_client3 = require("@uniformdev/next-app-router-client");
2858
2873
  var import_react4 = __toESM(require("react"));
2859
2874
 
2860
2875
  // src/config/helpers.ts
@@ -2907,7 +2922,7 @@ var UniformContext = async ({ clientContextComponent, result }) => {
2907
2922
  dynamicInputs: route.dynamicInputs,
2908
2923
  matchedRoute: route.matchedRoute
2909
2924
  } : void 0;
2910
- const ContextComponent = clientContextComponent || import_next_app_router_client2.DefaultUniformClientContext;
2925
+ const ContextComponent = clientContextComponent || import_next_app_router_client3.DefaultUniformClientContext;
2911
2926
  const disableDevTools = getDisabledDevTools();
2912
2927
  const defaultConsent = (_a = result == null ? void 0 : result.pageState.defaultConsent) != null ? _a : getDefaultConsent();
2913
2928
  const experimentalQuirkSerialization = getQuirkSerialization();
@@ -2924,14 +2939,14 @@ var UniformContext = async ({ clientContextComponent, result }) => {
2924
2939
  };
2925
2940
 
2926
2941
  // src/components/VisibilityRulesWrapper.tsx
2927
- var import_next_app_router_client3 = require("@uniformdev/next-app-router-client");
2942
+ var import_next_app_router_client4 = require("@uniformdev/next-app-router-client");
2928
2943
  var import_react5 = __toESM(require("react"));
2929
2944
  var VisibilityRulesWrapper = ({
2930
2945
  parameter,
2931
2946
  initialIsVisible,
2932
2947
  children
2933
2948
  }) => {
2934
- return /* @__PURE__ */ import_react5.default.createElement(import_next_app_router_client3.VisibilityRulesWrapperClient, { parameter, initialIsVisible }, children);
2949
+ return /* @__PURE__ */ import_react5.default.createElement(import_next_app_router_client4.VisibilityRulesWrapperClient, { parameter, initialIsVisible }, children);
2935
2950
  };
2936
2951
 
2937
2952
  // src/components/UniformComposition.tsx
@@ -2994,7 +3009,7 @@ async function UniformCompositionInner({
2994
3009
  route
2995
3010
  }
2996
3011
  }
2997
- )), (pageState.compositionState === CANVAS_EDITOR_STATE || pageState.compositionState === CANVAS_DRAFT_STATE) && /* @__PURE__ */ import_react6.default.createElement(import_next_app_router_client4.UniformScript, null));
3012
+ )), (pageState.compositionState === CANVAS_EDITOR_STATE || pageState.compositionState === CANVAS_DRAFT_STATE) && /* @__PURE__ */ import_react6.default.createElement(import_next_app_router_client5.UniformScript, null));
2998
3013
  }
2999
3014
  var resolveComponents = ({
3000
3015
  target,
@@ -3090,7 +3105,7 @@ var resolveComponents = ({
3090
3105
  }
3091
3106
  let tagElement = null;
3092
3107
  if (enrichmentTags == null ? void 0 : enrichmentTags.length) {
3093
- tagElement = (0, import_react6.createElement)(import_next_app_router_client4.ContextUpdateTransfer, {
3108
+ tagElement = (0, import_react6.createElement)(import_next_app_router_client5.ContextUpdateTransfer, {
3094
3109
  key: `${slotName}-${componentIndex}-tags`,
3095
3110
  update: {
3096
3111
  enrichments: enrichmentTags
@@ -3165,7 +3180,7 @@ var createResolvedComponent = ({
3165
3180
  componentId: component._id,
3166
3181
  pageState
3167
3182
  });
3168
- return (0, import_react6.createElement)(import_next_app_router_client4.Personalize, { ...personalizeProps, key });
3183
+ return (0, import_react6.createElement)(import_next_app_router_client5.Personalize, { ...personalizeProps, key });
3169
3184
  }
3170
3185
  if (component.type === CANVAS_TEST_TYPE) {
3171
3186
  const extractedTest = extractTest({
@@ -3601,7 +3616,8 @@ var generatePossiblePageStates = ({
3601
3616
  defaultConsent: void 0,
3602
3617
  previewMode: void 0,
3603
3618
  rules: void 0,
3604
- locale
3619
+ locale,
3620
+ isPrefetch: void 0
3605
3621
  };
3606
3622
  const allStates = generateStatesRecursively(dependencyMap, void 0, initialState);
3607
3623
  return allStates.map((payload) => (0, import_next_app_router_shared8.serializeEvaluationResult)({ payload }));
package/dist/index.mjs CHANGED
@@ -2749,6 +2749,13 @@ var createTestComponentProps = ({
2749
2749
  test
2750
2750
  }) => {
2751
2751
  var _a;
2752
+ if (pageState.isPrefetch) {
2753
+ return {
2754
+ ...common,
2755
+ index: void 0,
2756
+ test
2757
+ };
2758
+ }
2752
2759
  const component = resolveComponentFromPageState({
2753
2760
  pageState,
2754
2761
  componentId
@@ -2787,6 +2794,7 @@ var applyEditableParameters = ({
2787
2794
  };
2788
2795
 
2789
2796
  // src/components/Test.tsx
2797
+ import { ClientTest } from "@uniformdev/next-app-router-client";
2790
2798
  import { createElement, Fragment } from "react";
2791
2799
 
2792
2800
  // src/components/ContextTestTransfer.tsx
@@ -2799,7 +2807,14 @@ var ContextTestTransfer = ({ event }) => {
2799
2807
  // src/components/Test.tsx
2800
2808
  var Test = ({ index, slots, test, component, context: compositionContext }) => {
2801
2809
  var _a, _b, _c, _d, _e, _f;
2802
- const indexToShow = typeof index === "number" ? (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null : null;
2810
+ if (typeof index !== "number") {
2811
+ return createElement(ClientTest, {
2812
+ slots,
2813
+ test,
2814
+ context: compositionContext
2815
+ });
2816
+ }
2817
+ const indexToShow = (_b = (_a = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]) != null ? _b : null;
2803
2818
  const event = {
2804
2819
  name: test.name,
2805
2820
  control: (_d = (_c = test.variations[index]) == null ? void 0 : _c.control) != null ? _d : false,
@@ -3580,7 +3595,8 @@ var generatePossiblePageStates = ({
3580
3595
  defaultConsent: void 0,
3581
3596
  previewMode: void 0,
3582
3597
  rules: void 0,
3583
- locale
3598
+ locale,
3599
+ isPrefetch: void 0
3584
3600
  };
3585
3601
  const allStates = generateStatesRecursively(dependencyMap, void 0, initialState);
3586
3602
  return allStates.map((payload) => serializeEvaluationResult({ payload }));
@@ -3047,7 +3047,8 @@ var import_next_app_router_shared4 = require("@uniformdev/next-app-router-shared
3047
3047
  var evaluateRunnables = async ({
3048
3048
  runnables,
3049
3049
  context,
3050
- compositionContext
3050
+ compositionContext,
3051
+ isPrefetch
3051
3052
  }) => {
3052
3053
  var _a;
3053
3054
  const result = {
@@ -3057,6 +3058,9 @@ var evaluateRunnables = async ({
3057
3058
  const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3058
3059
  let item;
3059
3060
  while (item = runnablesToProcess.shift()) {
3061
+ if (item.type === "test" && isPrefetch) {
3062
+ continue;
3063
+ }
3060
3064
  if (item.type === "test") {
3061
3065
  const testResult = (0, import_next_app_router_shared4.evaluateTest)({
3062
3066
  context,
@@ -5562,7 +5566,8 @@ var handlePlaygroundRequest = async ({
5562
5566
  searchParams: request.nextUrl.searchParams,
5563
5567
  isDraftModeEnabled: true
5564
5568
  // this is checked above
5565
- })
5569
+ }),
5570
+ isPrefetch: false
5566
5571
  });
5567
5572
  const pageState = {
5568
5573
  routePath: id,
@@ -5580,7 +5585,8 @@ var handlePlaygroundRequest = async ({
5580
5585
  // this is checked above
5581
5586
  }),
5582
5587
  rules,
5583
- locale: options.locale
5588
+ locale: options.locale,
5589
+ isPrefetch: void 0
5584
5590
  };
5585
5591
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5586
5592
  payload: pageState
@@ -5629,7 +5635,7 @@ var handleRouteRequest = async ({
5629
5635
  })
5630
5636
  ]);
5631
5637
  if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5632
- return import_server.NextResponse.next();
5638
+ return import_server.NextResponse.rewrite(new URL("/404", request.url));
5633
5639
  }
5634
5640
  if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5635
5641
  return handleRedirect({ request, route: routeResult.route });
@@ -5664,6 +5670,7 @@ var handleRouteRequest = async ({
5664
5670
  searchParams: request.nextUrl.searchParams,
5665
5671
  isDraftModeEnabled: draftModeEnabled
5666
5672
  });
5673
+ const isPrefetch = isPrefetchRequest(request);
5667
5674
  const { components, rules } = await extractAndEvaluateRunnables({
5668
5675
  composition: route.compositionApiResponse.composition,
5669
5676
  routePath,
@@ -5681,7 +5688,8 @@ var handleRouteRequest = async ({
5681
5688
  searchParams: request.nextUrl.searchParams,
5682
5689
  isDraftModeEnabled: true
5683
5690
  // this is checked above
5684
- })
5691
+ }),
5692
+ isPrefetch
5685
5693
  });
5686
5694
  const pageState = {
5687
5695
  routePath,
@@ -5695,7 +5703,8 @@ var handleRouteRequest = async ({
5695
5703
  }),
5696
5704
  previewMode,
5697
5705
  rules,
5698
- locale: options.locale
5706
+ locale: options.locale,
5707
+ isPrefetch: isPrefetch || void 0
5699
5708
  };
5700
5709
  const code = (0, import_next_app_router_shared5.serializeEvaluationResult)({
5701
5710
  payload: pageState
@@ -5715,6 +5724,9 @@ var handleRouteRequest = async ({
5715
5724
  headers
5716
5725
  });
5717
5726
  };
5727
+ var isPrefetchRequest = (request) => {
5728
+ return request.headers.has("next-url");
5729
+ };
5718
5730
  var extractAndEvaluateRunnables = async ({
5719
5731
  composition,
5720
5732
  routePath,
@@ -5725,12 +5737,14 @@ var extractAndEvaluateRunnables = async ({
5725
5737
  releaseId,
5726
5738
  defaultConsent,
5727
5739
  keys,
5728
- previewMode
5740
+ previewMode,
5741
+ isPrefetch
5729
5742
  }) => {
5730
5743
  const extracted = extractRunnables(composition);
5731
5744
  const result = await evaluateRunnables({
5732
5745
  runnables: extracted,
5733
5746
  context,
5747
+ isPrefetch,
5734
5748
  compositionContext: {
5735
5749
  _id: composition._id,
5736
5750
  type: composition.type,
@@ -5748,7 +5762,8 @@ var extractAndEvaluateRunnables = async ({
5748
5762
  defaultConsent,
5749
5763
  previewMode,
5750
5764
  rules: void 0,
5751
- locale: void 0
5765
+ locale: void 0,
5766
+ isPrefetch: isPrefetch || void 0
5752
5767
  }
5753
5768
  }
5754
5769
  });
@@ -3039,7 +3039,8 @@ import {
3039
3039
  var evaluateRunnables = async ({
3040
3040
  runnables,
3041
3041
  context,
3042
- compositionContext
3042
+ compositionContext,
3043
+ isPrefetch
3043
3044
  }) => {
3044
3045
  var _a;
3045
3046
  const result = {
@@ -3049,6 +3050,9 @@ var evaluateRunnables = async ({
3049
3050
  const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3050
3051
  let item;
3051
3052
  while (item = runnablesToProcess.shift()) {
3053
+ if (item.type === "test" && isPrefetch) {
3054
+ continue;
3055
+ }
3052
3056
  if (item.type === "test") {
3053
3057
  const testResult = evaluateTest({
3054
3058
  context,
@@ -5554,7 +5558,8 @@ var handlePlaygroundRequest = async ({
5554
5558
  searchParams: request.nextUrl.searchParams,
5555
5559
  isDraftModeEnabled: true
5556
5560
  // this is checked above
5557
- })
5561
+ }),
5562
+ isPrefetch: false
5558
5563
  });
5559
5564
  const pageState = {
5560
5565
  routePath: id,
@@ -5572,7 +5577,8 @@ var handlePlaygroundRequest = async ({
5572
5577
  // this is checked above
5573
5578
  }),
5574
5579
  rules,
5575
- locale: options.locale
5580
+ locale: options.locale,
5581
+ isPrefetch: void 0
5576
5582
  };
5577
5583
  const code = serializeEvaluationResult({
5578
5584
  payload: pageState
@@ -5621,7 +5627,7 @@ var handleRouteRequest = async ({
5621
5627
  })
5622
5628
  ]);
5623
5629
  if (!(routeResult == null ? void 0 : routeResult.route) || ((_d = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _d.type) === "notFound") {
5624
- return NextResponse.next();
5630
+ return NextResponse.rewrite(new URL("/404", request.url));
5625
5631
  }
5626
5632
  if (((_e = routeResult == null ? void 0 : routeResult.route) == null ? void 0 : _e.type) === "redirect") {
5627
5633
  return handleRedirect({ request, route: routeResult.route });
@@ -5656,6 +5662,7 @@ var handleRouteRequest = async ({
5656
5662
  searchParams: request.nextUrl.searchParams,
5657
5663
  isDraftModeEnabled: draftModeEnabled
5658
5664
  });
5665
+ const isPrefetch = isPrefetchRequest(request);
5659
5666
  const { components, rules } = await extractAndEvaluateRunnables({
5660
5667
  composition: route.compositionApiResponse.composition,
5661
5668
  routePath,
@@ -5673,7 +5680,8 @@ var handleRouteRequest = async ({
5673
5680
  searchParams: request.nextUrl.searchParams,
5674
5681
  isDraftModeEnabled: true
5675
5682
  // this is checked above
5676
- })
5683
+ }),
5684
+ isPrefetch
5677
5685
  });
5678
5686
  const pageState = {
5679
5687
  routePath,
@@ -5687,7 +5695,8 @@ var handleRouteRequest = async ({
5687
5695
  }),
5688
5696
  previewMode,
5689
5697
  rules,
5690
- locale: options.locale
5698
+ locale: options.locale,
5699
+ isPrefetch: isPrefetch || void 0
5691
5700
  };
5692
5701
  const code = serializeEvaluationResult({
5693
5702
  payload: pageState
@@ -5707,6 +5716,9 @@ var handleRouteRequest = async ({
5707
5716
  headers
5708
5717
  });
5709
5718
  };
5719
+ var isPrefetchRequest = (request) => {
5720
+ return request.headers.has("next-url");
5721
+ };
5710
5722
  var extractAndEvaluateRunnables = async ({
5711
5723
  composition,
5712
5724
  routePath,
@@ -5717,12 +5729,14 @@ var extractAndEvaluateRunnables = async ({
5717
5729
  releaseId,
5718
5730
  defaultConsent,
5719
5731
  keys,
5720
- previewMode
5732
+ previewMode,
5733
+ isPrefetch
5721
5734
  }) => {
5722
5735
  const extracted = extractRunnables(composition);
5723
5736
  const result = await evaluateRunnables({
5724
5737
  runnables: extracted,
5725
5738
  context,
5739
+ isPrefetch,
5726
5740
  compositionContext: {
5727
5741
  _id: composition._id,
5728
5742
  type: composition.type,
@@ -5740,7 +5754,8 @@ var extractAndEvaluateRunnables = async ({
5740
5754
  defaultConsent,
5741
5755
  previewMode,
5742
5756
  rules: void 0,
5743
- locale: void 0
5757
+ locale: void 0,
5758
+ isPrefetch: isPrefetch || void 0
5744
5759
  }
5745
5760
  }
5746
5761
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/next-app-router",
3
- "version": "20.50.0",
3
+ "version": "20.50.1-alpha.16+940a311ed2",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -99,12 +99,12 @@
99
99
  "vitest": "3.2.4"
100
100
  },
101
101
  "dependencies": {
102
- "@uniformdev/canvas-react": "20.50.0",
103
- "@uniformdev/next-app-router-client": "20.50.0",
104
- "@uniformdev/next-app-router-shared": "20.50.0",
105
- "@uniformdev/redirect": "20.50.0",
106
- "@uniformdev/richtext": "20.50.0",
107
- "@uniformdev/webhooks": "20.50.0",
102
+ "@uniformdev/canvas-react": "20.50.1-alpha.16+940a311ed2",
103
+ "@uniformdev/next-app-router-client": "20.50.1-alpha.16+940a311ed2",
104
+ "@uniformdev/next-app-router-shared": "20.50.1-alpha.16+940a311ed2",
105
+ "@uniformdev/redirect": "20.50.1-alpha.16+940a311ed2",
106
+ "@uniformdev/richtext": "20.50.1-alpha.16+940a311ed2",
107
+ "@uniformdev/webhooks": "20.50.1-alpha.16+940a311ed2",
108
108
  "@vercel/functions": "^2.2.2",
109
109
  "encoding": "^0.1.13",
110
110
  "server-only": "^0.0.1",
@@ -121,5 +121,5 @@
121
121
  "publishConfig": {
122
122
  "access": "public"
123
123
  },
124
- "gitHead": "58f9d804c4f3e01abea765fa69202b540427e999"
124
+ "gitHead": "940a311ed2ab119a1d58fc652a91e1818fe746e8"
125
125
  }