@serwist/next 9.3.1 → 9.4.0
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.react.d.ts +7 -1
- package/dist/index.react.d.ts.map +1 -1
- package/dist/index.react.js +8 -13
- package/package.json +9 -9
- package/src/index.react.tsx +13 -7
package/dist/index.react.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ReactNode } from "react";
|
|
|
3
3
|
import { useSerwist } from "./lib/context.js";
|
|
4
4
|
export interface SerwistProviderProps {
|
|
5
5
|
swUrl: string;
|
|
6
|
+
disable?: boolean;
|
|
6
7
|
register?: boolean;
|
|
7
8
|
cacheOnNavigation?: boolean;
|
|
8
9
|
reloadOnOnline?: boolean;
|
|
@@ -14,6 +15,11 @@ declare global {
|
|
|
14
15
|
serwist: Serwist;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* `@serwist/window` provider for Next.js apps.
|
|
20
|
+
* @param options
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function SerwistProvider({ swUrl, disable, register, cacheOnNavigation, reloadOnOnline, options, children, }: SerwistProviderProps): import("react").JSX.Element;
|
|
18
24
|
export { useSerwist };
|
|
19
25
|
//# sourceMappingURL=index.react.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.react.d.ts","sourceRoot":"","sources":["../src/index.react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAkB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,QAAe,EACf,iBAAwB,EACxB,cAAqB,EACrB,OAAO,EACP,QAAQ,GACT,EAAE,oBAAoB,+
|
|
1
|
+
{"version":3,"file":"index.react.d.ts","sourceRoot":"","sources":["../src/index.react.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAkB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,OAAe,EACf,QAAe,EACf,iBAAwB,EACxB,cAAqB,EACrB,OAAO,EACP,QAAQ,GACT,EAAE,oBAAoB,+BAuDtB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/index.react.js
CHANGED
|
@@ -12,28 +12,23 @@ const useSerwist = ()=>{
|
|
|
12
12
|
return context;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
function SerwistProvider({ swUrl, register = true, cacheOnNavigation = true, reloadOnOnline = true, options, children }) {
|
|
15
|
+
function SerwistProvider({ swUrl, disable = false, register = true, cacheOnNavigation = true, reloadOnOnline = true, options, children }) {
|
|
16
16
|
const [serwist] = useState(()=>{
|
|
17
17
|
if (typeof window === "undefined") return null;
|
|
18
|
+
if (disable) return null;
|
|
19
|
+
const scope = options?.scope || "/";
|
|
18
20
|
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
19
21
|
window.serwist = new Serwist(swUrl, {
|
|
20
22
|
...options,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
scope,
|
|
24
|
+
type: options?.type || "module"
|
|
23
25
|
});
|
|
26
|
+
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
27
|
+
void window.serwist.register();
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
return window.serwist ?? null;
|
|
26
31
|
});
|
|
27
|
-
useEffect(()=>{
|
|
28
|
-
const scope = options?.scope || "/";
|
|
29
|
-
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
30
|
-
void serwist?.register();
|
|
31
|
-
}
|
|
32
|
-
}, [
|
|
33
|
-
register,
|
|
34
|
-
options?.scope,
|
|
35
|
-
serwist?.register
|
|
36
|
-
]);
|
|
37
32
|
useEffect(()=>{
|
|
38
33
|
const cacheUrls = async (url)=>{
|
|
39
34
|
if (!window.navigator.onLine || !url) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/next",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that integrates Serwist into your Next.js application.",
|
|
6
6
|
"files": [
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"kolorist": "1.8.0",
|
|
81
81
|
"semver": "7.7.3",
|
|
82
82
|
"zod": "4.2.1",
|
|
83
|
-
"@serwist/build": "9.
|
|
84
|
-
"@serwist/webpack-plugin": "9.
|
|
85
|
-
"@serwist/window": "9.
|
|
86
|
-
"serwist": "9.
|
|
83
|
+
"@serwist/build": "9.4.0",
|
|
84
|
+
"@serwist/webpack-plugin": "9.4.0",
|
|
85
|
+
"@serwist/window": "9.4.0",
|
|
86
|
+
"serwist": "9.4.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@types/node": "25.0.3",
|
|
@@ -96,15 +96,15 @@
|
|
|
96
96
|
"type-fest": "5.3.1",
|
|
97
97
|
"typescript": "5.9.3",
|
|
98
98
|
"webpack": "5.104.1",
|
|
99
|
-
"@serwist/cli": "9.
|
|
100
|
-
"@serwist/configs": "9.
|
|
101
|
-
"@serwist/utils": "9.
|
|
99
|
+
"@serwist/cli": "9.4.0",
|
|
100
|
+
"@serwist/configs": "9.4.0",
|
|
101
|
+
"@serwist/utils": "9.4.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"next": ">=14.0.0",
|
|
105
105
|
"react": ">=18.0.0",
|
|
106
106
|
"typescript": ">=5.0.0",
|
|
107
|
-
"@serwist/cli": "9.
|
|
107
|
+
"@serwist/cli": "^9.4.0"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@serwist/cli": {
|
package/src/index.react.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { SerwistContext, useSerwist } from "./lib/context.js";
|
|
|
5
5
|
|
|
6
6
|
export interface SerwistProviderProps {
|
|
7
7
|
swUrl: string;
|
|
8
|
+
disable?: boolean;
|
|
8
9
|
register?: boolean;
|
|
9
10
|
cacheOnNavigation?: boolean;
|
|
10
11
|
reloadOnOnline?: boolean;
|
|
@@ -18,8 +19,14 @@ declare global {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* `@serwist/window` provider for Next.js apps.
|
|
24
|
+
* @param options
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
21
27
|
export function SerwistProvider({
|
|
22
28
|
swUrl,
|
|
29
|
+
disable = false,
|
|
23
30
|
register = true,
|
|
24
31
|
cacheOnNavigation = true,
|
|
25
32
|
reloadOnOnline = true,
|
|
@@ -28,17 +35,16 @@ export function SerwistProvider({
|
|
|
28
35
|
}: SerwistProviderProps) {
|
|
29
36
|
const [serwist] = useState(() => {
|
|
30
37
|
if (typeof window === "undefined") return null;
|
|
38
|
+
if (disable) return null;
|
|
39
|
+
const scope = options?.scope || "/";
|
|
31
40
|
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
32
|
-
window.serwist = new Serwist(swUrl, { ...options, type: options?.type || "module"
|
|
41
|
+
window.serwist = new Serwist(swUrl, { ...options, scope, type: options?.type || "module" });
|
|
42
|
+
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
43
|
+
void window.serwist.register();
|
|
44
|
+
}
|
|
33
45
|
}
|
|
34
46
|
return window.serwist ?? null;
|
|
35
47
|
});
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
const scope = options?.scope || "/";
|
|
38
|
-
if (register && !isCurrentPageOutOfScope(scope)) {
|
|
39
|
-
void serwist?.register();
|
|
40
|
-
}
|
|
41
|
-
}, [register, options?.scope, serwist?.register]);
|
|
42
48
|
useEffect(() => {
|
|
43
49
|
const cacheUrls = async (url?: string | URL | null | undefined) => {
|
|
44
50
|
if (!window.navigator.onLine || !url) {
|