@serwist/next 9.0.0 → 9.0.2

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/README.md CHANGED
@@ -1 +1 @@
1
- This module's documentation can be found at https://serwist.pages.dev/docs/next
1
+ This module's documentation can be found at https://serwist.pages.dev/docs/next.
@@ -1 +1 @@
1
- {"version":3,"file":"sw-entry.d.ts","sourceRoot":"","sources":["../src/sw-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF"}
1
+ {"version":3,"file":"sw-entry.d.ts","sourceRoot":"","sources":["../src/sw-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM1C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF"}
package/dist/sw-entry.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { Serwist } from '@serwist/window';
2
+ import { isCurrentPageOutOfScope } from '@serwist/window/internal';
2
3
 
3
4
  if (typeof window !== "undefined" && "serviceWorker" in navigator && typeof caches !== "undefined") {
5
+ const scope = self.__SERWIST_SW_ENTRY.scope;
4
6
  let swEntryWorker;
5
7
  if (self.__SERWIST_SW_ENTRY.swEntryWorker) {
6
8
  swEntryWorker = new Worker(self.__SERWIST_SW_ENTRY.swEntryWorker);
7
9
  }
8
10
  window.serwist = new Serwist(window.location.origin + self.__SERWIST_SW_ENTRY.sw, {
9
- scope: self.__SERWIST_SW_ENTRY.scope
11
+ scope
10
12
  });
11
- if (self.__SERWIST_SW_ENTRY.register) {
13
+ if (self.__SERWIST_SW_ENTRY.register && !isCurrentPageOutOfScope(scope)) {
12
14
  window.serwist.register();
13
15
  }
14
16
  if (self.__SERWIST_SW_ENTRY.cacheOnNavigation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "9.0.0",
3
+ "version": "9.0.2",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -65,10 +65,10 @@
65
65
  "chalk": "5.3.0",
66
66
  "glob": "10.3.12",
67
67
  "zod": "3.22.4",
68
- "@serwist/build": "9.0.0",
69
- "@serwist/webpack-plugin": "9.0.0",
70
- "@serwist/window": "9.0.0",
71
- "serwist": "9.0.0"
68
+ "@serwist/build": "9.0.2",
69
+ "@serwist/webpack-plugin": "9.0.2",
70
+ "@serwist/window": "9.0.2",
71
+ "serwist": "9.0.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/node": "20.12.7",
@@ -79,8 +79,8 @@
79
79
  "type-fest": "4.15.0",
80
80
  "typescript": "5.5.0-dev.20240415",
81
81
  "webpack": "5.91.0",
82
- "@serwist/configs": "9.0.0",
83
- "@serwist/utils": "9.0.0"
82
+ "@serwist/configs": "9.0.2",
83
+ "@serwist/utils": "9.0.2"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "next": ">=14.0.0",
@@ -92,7 +92,7 @@
92
92
  }
93
93
  },
94
94
  "scripts": {
95
- "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
95
+ "build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",
96
96
  "dev": "rollup --config rollup.config.js --watch",
97
97
  "lint": "biome lint ./src",
98
98
  "typecheck": "tsc"
package/src/sw-entry.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Serwist } from "@serwist/window";
2
+ import { isCurrentPageOutOfScope } from "@serwist/window/internal";
2
3
 
3
4
  import type { SerwistNextOptions } from "./internal-types.js";
4
5
  import type { MessageType } from "./sw-entry-worker.js";
@@ -16,17 +17,17 @@ declare const self: Window &
16
17
  };
17
18
 
18
19
  if (typeof window !== "undefined" && "serviceWorker" in navigator && typeof caches !== "undefined") {
20
+ const scope = self.__SERWIST_SW_ENTRY.scope;
21
+
19
22
  let swEntryWorker: Worker | undefined;
20
23
 
21
24
  if (self.__SERWIST_SW_ENTRY.swEntryWorker) {
22
25
  swEntryWorker = new Worker(self.__SERWIST_SW_ENTRY.swEntryWorker);
23
26
  }
24
27
 
25
- window.serwist = new Serwist(window.location.origin + self.__SERWIST_SW_ENTRY.sw, {
26
- scope: self.__SERWIST_SW_ENTRY.scope,
27
- });
28
+ window.serwist = new Serwist(window.location.origin + self.__SERWIST_SW_ENTRY.sw, { scope });
28
29
 
29
- if (self.__SERWIST_SW_ENTRY.register) {
30
+ if (self.__SERWIST_SW_ENTRY.register && !isCurrentPageOutOfScope(scope)) {
30
31
  window.serwist.register();
31
32
  }
32
33