@sitecore-jss/sitecore-jss-nextjs 22.7.0-canary.10 → 22.7.0-canary.12

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.
@@ -24,11 +24,20 @@ class MiddlewareBase {
24
24
  * @returns {boolean} is prefetch
25
25
  */
26
26
  isPrefetch(req) {
27
- return (
28
- // eslint-disable-next-line prettier/prettier
29
- req.headers.get('purpose') === 'prefetch' || // Pages Router
30
- req.headers.get('Next-Router-Prefetch') === '1' // App Router
31
- );
27
+ const isMobile = req.headers.get('sec-ch-ua-mobile') === '?1';
28
+ const userAgent = req.headers.get('user-agent') || '';
29
+ const isKnownPlatform = /iPhone|Mac|Linux|Windows|Android/i.test(userAgent);
30
+ const isKnownDevice = isMobile || isKnownPlatform;
31
+ const purpose = req.headers.get('purpose');
32
+ const nextRouterPrefetch = req.headers.get('Next-Router-Prefetch');
33
+ const middlewarePrefetch = req.headers.get('x-middleware-prefetch');
34
+ // Some real navigations on different devices may incorrectly include 'prefetch' headers.
35
+ // To avoid skipping personalization in such cases, we treat 'x-middleware-prefetch' as a more reliable signal of true prefetch behavior.
36
+ if (isKnownDevice && middlewarePrefetch === '1') {
37
+ return false;
38
+ }
39
+ // Otherwise, standard prefetch detection
40
+ return purpose === 'prefetch' || nextRouterPrefetch === '1' || middlewarePrefetch === '1';
32
41
  }
33
42
  excludeRoute(pathname) {
34
43
  var _a, _b;
@@ -69,6 +69,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
69
69
  // Disable preflight caching to force revalidation on client-side navigation (personalization WILL be influenced).
70
70
  // Note the reason we don't move this any earlier in the middleware is that we would then be sacrificing performance for non-personalized pages.
71
71
  response.headers.set('x-middleware-cache', 'no-cache');
72
+ response.headers.set('Cache-Control', 'no-store, must-revalidate');
72
73
  return response;
73
74
  }
74
75
  yield this.initPersonalizeServer({
@@ -21,11 +21,20 @@ export class MiddlewareBase {
21
21
  * @returns {boolean} is prefetch
22
22
  */
23
23
  isPrefetch(req) {
24
- return (
25
- // eslint-disable-next-line prettier/prettier
26
- req.headers.get('purpose') === 'prefetch' || // Pages Router
27
- req.headers.get('Next-Router-Prefetch') === '1' // App Router
28
- );
24
+ const isMobile = req.headers.get('sec-ch-ua-mobile') === '?1';
25
+ const userAgent = req.headers.get('user-agent') || '';
26
+ const isKnownPlatform = /iPhone|Mac|Linux|Windows|Android/i.test(userAgent);
27
+ const isKnownDevice = isMobile || isKnownPlatform;
28
+ const purpose = req.headers.get('purpose');
29
+ const nextRouterPrefetch = req.headers.get('Next-Router-Prefetch');
30
+ const middlewarePrefetch = req.headers.get('x-middleware-prefetch');
31
+ // Some real navigations on different devices may incorrectly include 'prefetch' headers.
32
+ // To avoid skipping personalization in such cases, we treat 'x-middleware-prefetch' as a more reliable signal of true prefetch behavior.
33
+ if (isKnownDevice && middlewarePrefetch === '1') {
34
+ return false;
35
+ }
36
+ // Otherwise, standard prefetch detection
37
+ return purpose === 'prefetch' || nextRouterPrefetch === '1' || middlewarePrefetch === '1';
29
38
  }
30
39
  excludeRoute(pathname) {
31
40
  var _a, _b;
@@ -66,6 +66,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
66
66
  // Disable preflight caching to force revalidation on client-side navigation (personalization WILL be influenced).
67
67
  // Note the reason we don't move this any earlier in the middleware is that we would then be sacrificing performance for non-personalized pages.
68
68
  response.headers.set('x-middleware-cache', 'no-cache');
69
+ response.headers.set('Cache-Control', 'no-store, must-revalidate');
69
70
  return response;
70
71
  }
71
72
  yield this.initPersonalizeServer({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "22.7.0-canary.10",
3
+ "version": "22.7.0-canary.12",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -72,16 +72,16 @@
72
72
  "react-dom": "^19.1.0"
73
73
  },
74
74
  "dependencies": {
75
- "@sitecore-jss/sitecore-jss": "22.7.0-canary.10",
76
- "@sitecore-jss/sitecore-jss-dev-tools": "22.7.0-canary.10",
77
- "@sitecore-jss/sitecore-jss-react": "22.7.0-canary.10",
75
+ "@sitecore-jss/sitecore-jss": "22.7.0-canary.12",
76
+ "@sitecore-jss/sitecore-jss-dev-tools": "22.7.0-canary.12",
77
+ "@sitecore-jss/sitecore-jss-react": "22.7.0-canary.12",
78
78
  "@vercel/kv": "^0.2.1",
79
79
  "regex-parser": "^2.2.11",
80
80
  "sync-disk-cache": "^2.1.0"
81
81
  },
82
82
  "description": "",
83
83
  "types": "types/index.d.ts",
84
- "gitHead": "98bc01faa6487f50b8f39498af7eac98ecc86445",
84
+ "gitHead": "9d5d341cad45a2d275d543d742b2b897a3bbbc50",
85
85
  "files": [
86
86
  "dist",
87
87
  "types",