@sws2apps/react-sw-helper
Advanced tools
@@ -1,48 +0,47 @@ | ||
| import { useState as l, useCallback as g, useEffect as m } from "react"; | ||
| const y = !!((window == null ? void 0 : window.location.hostname) === "localhost" || (window == null ? void 0 : window.location.hostname) === "[::1]" || window != null && window.location.hostname.match( | ||
| import { useState as h, useCallback as r, useEffect as k } from "react"; | ||
| const m = !!(window?.location.hostname === "localhost" || window?.location.hostname === "[::1]" || window?.location.hostname.match( | ||
| /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ | ||
| )), $ = ({ | ||
| children: f, | ||
| onError: r, | ||
| onInstalled: s, | ||
| onUpdated: t, | ||
| onWaiting: u, | ||
| publicServiceWorkerDest: a, | ||
| publicUrl: o = "" | ||
| )), y = ({ | ||
| children: a, | ||
| onError: g, | ||
| onInstalled: w, | ||
| onUpdated: s, | ||
| onWaiting: v, | ||
| publicServiceWorkerDest: i, | ||
| publicUrl: t = "" | ||
| }) => { | ||
| const [n, h] = l(null), c = g(async () => { | ||
| const [o, l] = h(null), n = r(async () => { | ||
| try { | ||
| const e = await navigator.serviceWorker.getRegistration() || await navigator.serviceWorker.register( | ||
| `${o}${a}` | ||
| `${t}${i}` | ||
| ); | ||
| h(e), e != null && e.waiting && (console.log("Service Worker is in waiting state."), t == null || t()), e.addEventListener("updatefound", () => { | ||
| const i = e.installing || e.waiting; | ||
| i == null || i.addEventListener("statechange", () => { | ||
| i.state === "installed" && (navigator.serviceWorker.controller ? t == null || t() : s == null || s()); | ||
| l(e), e?.waiting && (console.log("Service Worker is in waiting state."), s?.()), e.addEventListener("updatefound", () => { | ||
| const c = e.installing || e.waiting; | ||
| c?.addEventListener("statechange", () => { | ||
| c.state === "installed" && (navigator.serviceWorker.controller ? s?.() : w?.()); | ||
| }); | ||
| }); | ||
| } catch (e) { | ||
| console.error("Error during service worker registration:", e), r == null || r(e); | ||
| console.error("Error during service worker registration:", e), g?.(e); | ||
| } | ||
| }, [ | ||
| o, | ||
| a, | ||
| r, | ||
| u, | ||
| s, | ||
| t | ||
| ]), w = g(async () => { | ||
| var e; | ||
| t, | ||
| i, | ||
| g, | ||
| v, | ||
| w, | ||
| s | ||
| ]), f = r(async () => { | ||
| try { | ||
| const i = await fetch(`${o}${a}`); | ||
| i.status === 404 || !((e = i.headers.get("content-type")) != null && e.includes("javascript")) ? (await (await navigator.serviceWorker.ready).unregister(), window.location.reload()) : c(); | ||
| } catch (i) { | ||
| const e = await fetch(`${t}${i}`); | ||
| e.status === 404 || !e.headers.get("content-type")?.includes("javascript") ? (await (await navigator.serviceWorker.ready).unregister(), window.location.reload()) : n(); | ||
| } catch (e) { | ||
| console.log( | ||
| "No internet connection found. App is running in offline mode.", | ||
| i | ||
| e | ||
| ); | ||
| } | ||
| }, [o, a, c]), v = g(() => { | ||
| }, [t, i, n]), d = r(() => { | ||
| if ("serviceWorker" in navigator) { | ||
| if (new URL(o, window.location.href).origin !== window.location.origin) { | ||
| if (new URL(t, window.location.href).origin !== window.location.origin) { | ||
| console.warn( | ||
@@ -53,13 +52,13 @@ "Service worker cannot be registered because PUBLIC_URL is on a different origin from page." | ||
| } | ||
| y ? w() : c(); | ||
| m ? f() : n(); | ||
| } | ||
| }, [o, w, c]), k = g(() => { | ||
| n && (n.update(), n.waiting && n.waiting.postMessage({ type: "SKIP_WAITING" })); | ||
| }, [n]); | ||
| return m(() => { | ||
| process.env.NODE_ENV === "production" && v(); | ||
| }, [v]), typeof f == "function" ? f({ update: k }) : f; | ||
| }, [t, f, n]), u = r(() => { | ||
| o && (o.update(), o.waiting && o.waiting.postMessage({ type: "SKIP_WAITING" })); | ||
| }, [o]); | ||
| return k(() => { | ||
| process.env.NODE_ENV === "production" && d(); | ||
| }, [d]), typeof a == "function" ? a({ update: u }) : a; | ||
| }; | ||
| export { | ||
| $ as default | ||
| y as default | ||
| }; |
@@ -1,1 +0,1 @@ | ||
| (function(i,r){typeof exports=="object"&&typeof module<"u"?module.exports=r(require("react")):typeof define=="function"&&define.amd?define(["react"],r):(i=typeof globalThis<"u"?globalThis:i||self,i.ServiceWorkerWrapper=r(i.React))})(this,function(i){"use strict";const r=!!((window==null?void 0:window.location.hostname)==="localhost"||(window==null?void 0:window.location.hostname)==="[::1]"||window!=null&&window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));return({children:w,onError:a,onInstalled:c,onUpdated:n,onWaiting:h,publicServiceWorkerDest:f,publicUrl:o=""})=>{const[s,k]=i.useState(null),g=i.useCallback(async()=>{try{const e=await navigator.serviceWorker.getRegistration()||await navigator.serviceWorker.register(`${o}${f}`);k(e),e!=null&&e.waiting&&(console.log("Service Worker is in waiting state."),n==null||n()),e.addEventListener("updatefound",()=>{const t=e.installing||e.waiting;t==null||t.addEventListener("statechange",()=>{t.state==="installed"&&(navigator.serviceWorker.controller?n==null||n():c==null||c())})})}catch(e){console.error("Error during service worker registration:",e),a==null||a(e)}},[o,f,a,h,c,n]),u=i.useCallback(async()=>{var e;try{const t=await fetch(`${o}${f}`);t.status===404||!((e=t.headers.get("content-type"))!=null&&e.includes("javascript"))?(await(await navigator.serviceWorker.ready).unregister(),window.location.reload()):g()}catch(t){console.log("No internet connection found. App is running in offline mode.",t)}},[o,f,g]),v=i.useCallback(()=>{if("serviceWorker"in navigator){if(new URL(o,window.location.href).origin!==window.location.origin){console.warn("Service worker cannot be registered because PUBLIC_URL is on a different origin from page.");return}r?u():g()}},[o,u,g]),l=i.useCallback(()=>{s&&(s.update(),s.waiting&&s.waiting.postMessage({type:"SKIP_WAITING"}))},[s]);return i.useEffect(()=>{process.env.NODE_ENV==="production"&&v()},[v]),typeof w=="function"?w({update:l}):w}}); | ||
| (function(t,n){typeof exports=="object"&&typeof module<"u"?module.exports=n(require("react")):typeof define=="function"&&define.amd?define(["react"],n):(t=typeof globalThis<"u"?globalThis:t||self,t.ServiceWorkerWrapper=n(t.React))})(this,function(t){"use strict";const n=!!(window?.location.hostname==="localhost"||window?.location.hostname==="[::1]"||window?.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));return({children:a,onError:g,onInstalled:d,onUpdated:c,onWaiting:l,publicServiceWorkerDest:r,publicUrl:i=""})=>{const[o,v]=t.useState(null),s=t.useCallback(async()=>{try{const e=await navigator.serviceWorker.getRegistration()||await navigator.serviceWorker.register(`${i}${r}`);v(e),e?.waiting&&(console.log("Service Worker is in waiting state."),c?.()),e.addEventListener("updatefound",()=>{const f=e.installing||e.waiting;f?.addEventListener("statechange",()=>{f.state==="installed"&&(navigator.serviceWorker.controller?c?.():d?.())})})}catch(e){console.error("Error during service worker registration:",e),g?.(e)}},[i,r,g,l,d,c]),w=t.useCallback(async()=>{try{const e=await fetch(`${i}${r}`);e.status===404||!e.headers.get("content-type")?.includes("javascript")?(await(await navigator.serviceWorker.ready).unregister(),window.location.reload()):s()}catch(e){console.log("No internet connection found. App is running in offline mode.",e)}},[i,r,s]),u=t.useCallback(()=>{if("serviceWorker"in navigator){if(new URL(i,window.location.href).origin!==window.location.origin){console.warn("Service worker cannot be registered because PUBLIC_URL is on a different origin from page.");return}n?w():s()}},[i,w,s]),k=t.useCallback(()=>{o&&(o.update(),o.waiting&&o.waiting.postMessage({type:"SKIP_WAITING"}))},[o]);return t.useEffect(()=>{process.env.NODE_ENV==="production"&&u()},[u]),typeof a=="function"?a({update:k}):a}}); |
+4
-4
| { | ||
| "name": "@sws2apps/react-sw-helper", | ||
| "description": "A pure react component library to handle service worker", | ||
| "version": "1.28.0", | ||
| "version": "1.29.0", | ||
| "type": "module", | ||
@@ -63,6 +63,6 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "@vitejs/plugin-react": "^4.0.0", | ||
| "@vitejs/plugin-react": "^5.0.2", | ||
| "react": "^19.1.0", | ||
| "react-dom": "^19.1.0", | ||
| "vite": "^6.0.2" | ||
| "vite": "^7.0.0" | ||
| }, | ||
@@ -73,3 +73,3 @@ "devDependencies": { | ||
| "@semantic-release/git": "^10.0.1", | ||
| "@types/node": "^22.0.0", | ||
| "@types/node": "^24.0.0", | ||
| "@types/react": "^19.0.12", | ||
@@ -76,0 +76,0 @@ "@typescript-eslint/eslint-plugin": "^8.0.0", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
11101
-2.54%86
-1.15%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated