@uniformdev/next-app-router 20.76.1-alpha.3 → 20.76.3-alpha.7.sha-dd3877d123

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.
@@ -2999,9 +2999,7 @@ var DefaultDataClient = class {
2999
2999
  source: "middleware",
3000
3000
  route: options.route,
3001
3001
  routeClient,
3002
- // The runtime cache is keyed on the route path. Development bypasses it so an author sees
3003
- // an edit right away, the same way the fetch cache is bypassed for development.
3004
- enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache() && !isDevelopmentEnvironment(),
3002
+ enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache(),
3005
3003
  disableSwrCache: getDisableSwrMiddlewareCache()
3006
3004
  });
3007
3005
  if (resolvedRoute.type === "composition") {
@@ -3058,75 +3056,6 @@ var DefaultDataClient = class {
3058
3056
  }
3059
3057
  };
3060
3058
 
3061
- // src/middleware/composition/evaluate/evaluateRunnables.ts
3062
- import {
3063
- evaluatePersonalization,
3064
- evaluateTest
3065
- } from "@uniformdev/next-app-router-shared";
3066
- var evaluateRunnables = async ({
3067
- runnables,
3068
- context,
3069
- compositionContext,
3070
- isPrefetch
3071
- }) => {
3072
- var _a;
3073
- const result = {
3074
- components: {},
3075
- rules: void 0
3076
- };
3077
- const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3078
- let item;
3079
- while (item = runnablesToProcess.shift()) {
3080
- if (item.type === "test" && isPrefetch) {
3081
- continue;
3082
- }
3083
- if (item.type === "test") {
3084
- const testResult = evaluateTest({
3085
- context,
3086
- test: item.result,
3087
- compositionContext
3088
- });
3089
- if (testResult.index !== null) {
3090
- result.components[item._id] = {
3091
- indexes: [testResult.index]
3092
- };
3093
- if (testResult.componentId) {
3094
- const dependentRunnables = runnables.filter((r) => r.variantId === testResult.componentId);
3095
- runnablesToProcess.push(...dependentRunnables);
3096
- }
3097
- }
3098
- } else if (item.type === "personalization") {
3099
- const personalizationResult = evaluatePersonalization({
3100
- context,
3101
- personalization: item.result,
3102
- compositionContext
3103
- });
3104
- if (personalizationResult.indexes.length) {
3105
- result.components[item._id] = {
3106
- indexes: personalizationResult.indexes
3107
- };
3108
- }
3109
- if (personalizationResult.componentIds.length) {
3110
- const dependentRunnables = runnables.filter(
3111
- (r) => r.variantId && personalizationResult.componentIds.includes(r.variantId)
3112
- );
3113
- runnablesToProcess.push(...dependentRunnables);
3114
- }
3115
- } else if (item.type === "visibility") {
3116
- const rules = createQuirksVisibilityRule(context.quirks);
3117
- const isVisible = evaluateNodeVisibilityParameter({
3118
- rules,
3119
- parameter: item.rules
3120
- });
3121
- if (isVisible !== null) {
3122
- result.rules = (_a = result.rules) != null ? _a : {};
3123
- result.rules[item._id] = isVisible;
3124
- }
3125
- }
3126
- }
3127
- return result;
3128
- };
3129
-
3130
3059
  // src/data/extract/extractRunnables.ts
3131
3060
  import { getRuleId } from "@uniformdev/next-app-router-shared";
3132
3061
 
@@ -3243,41 +3172,6 @@ var extractRunnables = (composition) => {
3243
3172
  return runnable;
3244
3173
  };
3245
3174
 
3246
- // src/data/evaluate/evaluatePageState.ts
3247
- var evaluatePageState = async ({
3248
- composition,
3249
- matchedRoute,
3250
- dynamicInputs,
3251
- pageState,
3252
- context
3253
- }) => {
3254
- const extracted = extractRunnables(composition);
3255
- const result = await evaluateRunnables({
3256
- runnables: extracted,
3257
- context,
3258
- isPrefetch: pageState.isPrefetch,
3259
- compositionContext: {
3260
- _id: composition._id,
3261
- type: composition.type,
3262
- state: pageState.compositionState,
3263
- isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
3264
- matchedRoute,
3265
- dynamicInputs,
3266
- pageState: {
3267
- ...pageState,
3268
- // empty for now, we need to pass composition metadata down to evaluateRunnables for Context events enrichment
3269
- components: {},
3270
- rules: void 0
3271
- }
3272
- }
3273
- });
3274
- const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
3275
- return {
3276
- ...result,
3277
- allComponentIds
3278
- };
3279
- };
3280
-
3281
3175
  // src/data/routes.ts
3282
3176
  var findRouteMatch = (routes, path) => {
3283
3177
  const pieces = path.split("/").filter(Boolean);
@@ -3309,6 +3203,75 @@ var findRouteMatch = (routes, path) => {
3309
3203
  return void 0;
3310
3204
  };
3311
3205
 
3206
+ // src/middleware/composition/evaluate/evaluateRunnables.ts
3207
+ import {
3208
+ evaluatePersonalization,
3209
+ evaluateTest
3210
+ } from "@uniformdev/next-app-router-shared";
3211
+ var evaluateRunnables = async ({
3212
+ runnables,
3213
+ context,
3214
+ compositionContext,
3215
+ isPrefetch
3216
+ }) => {
3217
+ var _a;
3218
+ const result = {
3219
+ components: {},
3220
+ rules: void 0
3221
+ };
3222
+ const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
3223
+ let item;
3224
+ while (item = runnablesToProcess.shift()) {
3225
+ if (item.type === "test" && isPrefetch) {
3226
+ continue;
3227
+ }
3228
+ if (item.type === "test") {
3229
+ const testResult = evaluateTest({
3230
+ context,
3231
+ test: item.result,
3232
+ compositionContext
3233
+ });
3234
+ if (testResult.index !== null) {
3235
+ result.components[item._id] = {
3236
+ indexes: [testResult.index]
3237
+ };
3238
+ if (testResult.componentId) {
3239
+ const dependentRunnables = runnables.filter((r) => r.variantId === testResult.componentId);
3240
+ runnablesToProcess.push(...dependentRunnables);
3241
+ }
3242
+ }
3243
+ } else if (item.type === "personalization") {
3244
+ const personalizationResult = evaluatePersonalization({
3245
+ context,
3246
+ personalization: item.result,
3247
+ compositionContext
3248
+ });
3249
+ if (personalizationResult.indexes.length) {
3250
+ result.components[item._id] = {
3251
+ indexes: personalizationResult.indexes
3252
+ };
3253
+ }
3254
+ if (personalizationResult.componentIds.length) {
3255
+ const dependentRunnables = runnables.filter(
3256
+ (r) => r.variantId && personalizationResult.componentIds.includes(r.variantId)
3257
+ );
3258
+ runnablesToProcess.push(...dependentRunnables);
3259
+ }
3260
+ } else if (item.type === "visibility") {
3261
+ const rules = createQuirksVisibilityRule(context.quirks);
3262
+ const isVisible = evaluateNodeVisibilityParameter({
3263
+ rules,
3264
+ parameter: item.rules
3265
+ });
3266
+ if (isVisible !== null) {
3267
+ result.rules = (_a = result.rules) != null ? _a : {};
3268
+ result.rules[item._id] = isVisible;
3269
+ }
3270
+ }
3271
+ }
3272
+ return result;
3273
+ };
3274
+
3312
3275
  // ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/lite/index.mjs
3313
3276
  var has = Object.prototype.hasOwnProperty;
3314
3277
  function dequal(foo, bar) {
@@ -5517,8 +5480,7 @@ var dc2 = (0, import_rfdc3.default)();
5517
5480
 
5518
5481
  // src/middleware/context/index.ts
5519
5482
  var createOnDemandContext = async (options) => {
5520
- var _a;
5521
- const manifest = await options.dataClient.getManifest({ source: (_a = options.source) != null ? _a : "middleware" });
5483
+ const manifest = await options.dataClient.getManifest({ source: "middleware" });
5522
5484
  if (!manifest) {
5523
5485
  console.error("Uniform manifest not found, falling back to empty manifest");
5524
5486
  }
@@ -5642,22 +5604,6 @@ var determineState = async ({
5642
5604
  return isDraftMode ? (isCanvasEditing ? [CANVAS_EDITOR_STATE] : []).concat([CANVAS_DRAFT_STATE]) : [CANVAS_PUBLISHED_STATE];
5643
5605
  };
5644
5606
 
5645
- // src/utils/quirks.ts
5646
- var buildQuirksFromHeaders = (headers) => {
5647
- const headerToQuirkKey = {
5648
- "x-vercel-ip-country": "vc-country",
5649
- "x-vercel-ip-country-region": "vc-region",
5650
- "x-vercel-ip-city": "vc-city"
5651
- };
5652
- return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
5653
- const value = headers.get(headerName);
5654
- if (value) {
5655
- acc[quirkKey] = value;
5656
- }
5657
- return acc;
5658
- }, {});
5659
- };
5660
-
5661
5607
  // src/middleware.ts
5662
5608
  var uniformMiddleware = (options) => {
5663
5609
  return async (request) => {
@@ -5696,11 +5642,26 @@ var isPlaygroundPath = (path) => {
5696
5642
  );
5697
5643
  return (match == null ? void 0 : match.route.id) === PLAYGROUND_ID ? match : void 0;
5698
5644
  };
5645
+ var buildQuirksFromHeaders = (headers) => {
5646
+ const headerToQuirkKey = {
5647
+ "x-vercel-ip-country": "vc-country",
5648
+ "x-vercel-ip-country-region": "vc-region",
5649
+ "x-vercel-ip-city": "vc-city"
5650
+ };
5651
+ return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
5652
+ const value = headers.get(headerName);
5653
+ if (value) {
5654
+ acc[quirkKey] = value;
5655
+ }
5656
+ return acc;
5657
+ }, {});
5658
+ };
5699
5659
  var handlePlaygroundRequest = async ({
5700
5660
  request,
5701
- options
5661
+ options,
5662
+ dataClient
5702
5663
  }) => {
5703
- var _a;
5664
+ var _a, _b;
5704
5665
  const id = request.nextUrl.searchParams.get("id");
5705
5666
  if (!id) {
5706
5667
  return NextResponse.json(
@@ -5742,12 +5703,41 @@ var handlePlaygroundRequest = async ({
5742
5703
  }
5743
5704
  const serverConfig = getServerConfig();
5744
5705
  const playgroundPath = getPlaygroundPath();
5706
+ const onDemandContext = await createOnDemandContext({
5707
+ cookies: request.cookies,
5708
+ dataClient,
5709
+ defaultConsent: determineDefaultConsent({
5710
+ serverConfig,
5711
+ defaultConsent: options.defaultConsent
5712
+ })
5713
+ });
5714
+ const context = await onDemandContext.getContext();
5715
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5716
+ composition: composition.composition,
5717
+ routePath: id,
5718
+ state: composition.state,
5719
+ context,
5720
+ matchedRoute: id,
5721
+ dynamicInputs: {},
5722
+ releaseId: (_a = options.release) == null ? void 0 : _a.id,
5723
+ defaultConsent: determineDefaultConsent({
5724
+ serverConfig,
5725
+ defaultConsent: options.defaultConsent
5726
+ }),
5727
+ keys: void 0,
5728
+ previewMode: determinePreviewMode({
5729
+ searchParams: request.nextUrl.searchParams,
5730
+ isDraftModeEnabled: true
5731
+ // this is checked above
5732
+ }),
5733
+ isPrefetch: false
5734
+ });
5745
5735
  const pageState = {
5746
5736
  routePath: id,
5747
5737
  compositionState: composition.state,
5748
- components: {},
5738
+ components,
5749
5739
  keys: void 0,
5750
- releaseId: (_a = options.release) == null ? void 0 : _a.id,
5740
+ releaseId: (_b = options.release) == null ? void 0 : _b.id,
5751
5741
  defaultConsent: determineDefaultConsent({
5752
5742
  serverConfig,
5753
5743
  defaultConsent: options.defaultConsent
@@ -5757,13 +5747,13 @@ var handlePlaygroundRequest = async ({
5757
5747
  isDraftModeEnabled: true
5758
5748
  // this is checked above
5759
5749
  }),
5760
- rules: void 0,
5750
+ rules,
5761
5751
  locale: options.locale,
5762
- isPrefetch: void 0,
5763
- requestPath: `${request.nextUrl.pathname}${request.nextUrl.search}`
5752
+ isPrefetch: void 0
5764
5753
  };
5765
5754
  const code = serializeEvaluationResult({
5766
- payload: pageState
5755
+ payload: pageState,
5756
+ allComponentIds
5767
5757
  });
5768
5758
  let pathToRewriteTo = await (options.rewriteDestinationPath ? options.rewriteDestinationPath({ code, pageState, source: "playground" }) : void 0);
5769
5759
  if (!pathToRewriteTo) {
@@ -5846,10 +5836,30 @@ var handleRouteRequest = async ({
5846
5836
  isDraftModeEnabled: draftModeEnabled
5847
5837
  });
5848
5838
  const isPrefetch = isPrefetchRequest(request);
5849
- const basePageState = {
5839
+ const { components, rules, allComponentIds } = await extractAndEvaluateRunnables({
5840
+ composition: route.compositionApiResponse.composition,
5841
+ routePath,
5842
+ state,
5843
+ context,
5844
+ matchedRoute: route.matchedRoute,
5845
+ dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5846
+ releaseId,
5847
+ defaultConsent: determineDefaultConsent({
5848
+ serverConfig,
5849
+ defaultConsent: options.defaultConsent
5850
+ }),
5851
+ keys: requestPath.keys,
5852
+ previewMode: determinePreviewMode({
5853
+ searchParams: request.nextUrl.searchParams,
5854
+ isDraftModeEnabled: true
5855
+ // this is checked above
5856
+ }),
5857
+ isPrefetch
5858
+ });
5859
+ const pageState = {
5850
5860
  routePath,
5851
5861
  compositionState: state,
5852
- components: {},
5862
+ components,
5853
5863
  keys: requestPath.keys,
5854
5864
  releaseId,
5855
5865
  defaultConsent: determineDefaultConsent({
@@ -5857,32 +5867,10 @@ var handleRouteRequest = async ({
5857
5867
  defaultConsent: options.defaultConsent
5858
5868
  }),
5859
5869
  previewMode,
5860
- rules: void 0,
5870
+ rules,
5861
5871
  locale: options.locale,
5862
- isPrefetch: isPrefetch || void 0,
5863
- // Draft requests evaluate while the page renders, so they carry with them the inputs that
5864
- // cannot be derived again there: the request path, and any custom quirks the consumer
5865
- // supplied to the middleware. Quirks from request headers are rebuilt at render time.
5866
- requestPath: draftModeEnabled ? `${request.nextUrl.pathname}${request.nextUrl.search}` : void 0,
5867
- quirks: draftModeEnabled ? options.quirks : void 0
5872
+ isPrefetch: isPrefetch || void 0
5868
5873
  };
5869
- let pageState = basePageState;
5870
- let allComponentIds = void 0;
5871
- if (!draftModeEnabled) {
5872
- const evaluated = await evaluatePageState({
5873
- composition: route.compositionApiResponse.composition,
5874
- matchedRoute: route.matchedRoute,
5875
- dynamicInputs: (_g = route.dynamicInputs) != null ? _g : {},
5876
- pageState: basePageState,
5877
- context
5878
- });
5879
- pageState = {
5880
- ...basePageState,
5881
- components: evaluated.components,
5882
- rules: evaluated.rules
5883
- };
5884
- allComponentIds = evaluated.allComponentIds;
5885
- }
5886
5874
  const code = serializeEvaluationResult({
5887
5875
  payload: pageState,
5888
5876
  allComponentIds
@@ -5905,6 +5893,49 @@ var handleRouteRequest = async ({
5905
5893
  var isPrefetchRequest = (request) => {
5906
5894
  return request.headers.has("next-url");
5907
5895
  };
5896
+ var extractAndEvaluateRunnables = async ({
5897
+ composition,
5898
+ routePath,
5899
+ context,
5900
+ state,
5901
+ matchedRoute,
5902
+ dynamicInputs,
5903
+ releaseId,
5904
+ defaultConsent,
5905
+ keys,
5906
+ previewMode,
5907
+ isPrefetch
5908
+ }) => {
5909
+ const extracted = extractRunnables(composition);
5910
+ const result = await evaluateRunnables({
5911
+ runnables: extracted,
5912
+ context,
5913
+ isPrefetch,
5914
+ compositionContext: {
5915
+ _id: composition._id,
5916
+ type: composition.type,
5917
+ state,
5918
+ isContextualEditing: state === CANVAS_EDITOR_STATE,
5919
+ matchedRoute,
5920
+ dynamicInputs,
5921
+ pageState: {
5922
+ routePath,
5923
+ compositionState: state,
5924
+ // empty for now, we need to pass composition metadata down to evaluateRunnables for Context events enrichment
5925
+ components: {},
5926
+ keys,
5927
+ releaseId,
5928
+ defaultConsent,
5929
+ previewMode,
5930
+ rules: void 0,
5931
+ locale: void 0,
5932
+ isPrefetch: isPrefetch || void 0
5933
+ }
5934
+ }
5935
+ });
5936
+ const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
5937
+ return { ...result, allComponentIds };
5938
+ };
5908
5939
  var handleRedirect = ({ request, route }) => {
5909
5940
  const href = resolveRedirectHref({
5910
5941
  resolveResult: route,
@@ -5927,7 +5958,7 @@ var buildRoutePath = ({
5927
5958
  pathname,
5928
5959
  route
5929
5960
  }) => {
5930
- var _a, _b, _c, _d;
5961
+ var _a, _b, _c;
5931
5962
  const [routePath, search] = pathname.split("?");
5932
5963
  const locale = (_a = route.dynamicInputs) == null ? void 0 : _a.locale;
5933
5964
  const projectMapNode = (_b = route.compositionApiResponse.composition.projectMapNodes) == null ? void 0 : _b.find((node) => {
@@ -5942,12 +5973,22 @@ var buildRoutePath = ({
5942
5973
  });
5943
5974
  const searchParams = new URLSearchParams();
5944
5975
  if ((_c = projectMapNode == null ? void 0 : projectMapNode.data) == null ? void 0 : _c.queryStrings) {
5945
- const existingSearchParams = search ? new URLSearchParams(search) : void 0;
5976
+ if (search) {
5977
+ const existingSearchParams = new URLSearchParams(search);
5978
+ for (const [key, value] of existingSearchParams.entries()) {
5979
+ searchParams.set(key, value);
5980
+ }
5981
+ }
5946
5982
  for (const qs of projectMapNode.data.queryStrings) {
5947
- const existingValue = existingSearchParams == null ? void 0 : existingSearchParams.get(qs.name);
5948
- searchParams.set(qs.name, (_d = existingValue != null ? existingValue : qs.value) != null ? _d : "");
5983
+ if (!searchParams.has(qs.name)) {
5984
+ const qsValue = qs.value;
5985
+ searchParams.set(qs.name, qsValue != null ? qsValue : "");
5986
+ }
5949
5987
  }
5950
5988
  }
5989
+ if (process.env.NODE_ENV === "development") {
5990
+ searchParams.set("cache", (/* @__PURE__ */ new Date()).valueOf().toString());
5991
+ }
5951
5992
  if (searchParams.size) {
5952
5993
  return `${routePath}?${searchParams.toString()}`;
5953
5994
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/next-app-router",
3
- "version": "20.76.1-alpha.3+61820b0b3e",
3
+ "version": "20.76.3-alpha.7.sha-dd3877d123",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -92,20 +92,20 @@
92
92
  "@types/node": "26.0.0",
93
93
  "@types/react": "19.2.17",
94
94
  "@types/react-dom": "19.2.3",
95
- "next": "16.2.9",
95
+ "next": "16.3.1",
96
96
  "react": "19.2.1",
97
97
  "react-dom": "19.2.1",
98
98
  "typescript": "6.0.3",
99
99
  "vite-tsconfig-paths": "^6.1.1",
100
- "vitest": "4.1.9"
100
+ "vitest": "4.1.11"
101
101
  },
102
102
  "dependencies": {
103
- "@uniformdev/canvas-react": "20.76.1-alpha.3+61820b0b3e",
104
- "@uniformdev/next-app-router-client": "20.76.1-alpha.3+61820b0b3e",
105
- "@uniformdev/next-app-router-shared": "20.76.1-alpha.3+61820b0b3e",
106
- "@uniformdev/redirect": "20.76.1-alpha.3+61820b0b3e",
107
- "@uniformdev/richtext": "20.76.1-alpha.3+61820b0b3e",
108
- "@uniformdev/webhooks": "20.76.1-alpha.3+61820b0b3e",
103
+ "@uniformdev/canvas-react": "20.76.3-alpha.7.sha-dd3877d123",
104
+ "@uniformdev/next-app-router-client": "20.76.3-alpha.7.sha-dd3877d123",
105
+ "@uniformdev/next-app-router-shared": "20.76.3-alpha.7.sha-dd3877d123",
106
+ "@uniformdev/redirect": "20.76.3-alpha.7.sha-dd3877d123",
107
+ "@uniformdev/richtext": "20.76.3-alpha.7.sha-dd3877d123",
108
+ "@uniformdev/webhooks": "20.76.3-alpha.7.sha-dd3877d123",
109
109
  "@vercel/functions": "^3.7.2",
110
110
  "encoding": "^0.1.13",
111
111
  "server-only": "^0.0.1",
@@ -122,5 +122,5 @@
122
122
  "publishConfig": {
123
123
  "access": "public"
124
124
  },
125
- "gitHead": "61820b0b3e1be2512bcfad6bd0a30092ffa7f9a3"
125
+ "gitHead": "dd3877d123e16a160c58c1e258aee070565a4fc7"
126
126
  }