Trying to resolve SW issues.
This commit is contained in:
@@ -19,7 +19,6 @@ import GlobalLoadingBar from "../components/global-loading-bar/global-loading-ba
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
import errorLink from "../graphql/apollo-error-handling";
|
||||
import App from "./App";
|
||||
import RegisterServiceWorker from "./registerServiceWorker.component";
|
||||
|
||||
moment.locale("en-US");
|
||||
|
||||
@@ -152,7 +151,6 @@ export default function AppContainer() {
|
||||
locale={enLocale}
|
||||
>
|
||||
<GlobalLoadingBar />
|
||||
<RegisterServiceWorker />
|
||||
<App />
|
||||
</ConfigProvider>
|
||||
</ApolloProvider>
|
||||
|
||||
@@ -1,48 +1,42 @@
|
||||
import { AlertOutlined } from "@ant-design/icons";
|
||||
import { Button, notification } from "antd";
|
||||
import i18n from "i18next";
|
||||
import React, { useEffect } from "react";
|
||||
import React from "react";
|
||||
import * as serviceWorker from "../serviceWorker";
|
||||
|
||||
export default function RegisterServiceWorker() {
|
||||
useEffect(() => {
|
||||
console.log("SWR Use Effect Fired.");
|
||||
const onServiceWorkerUpdate = (registration) => {
|
||||
console.log("onServiceWorkerUpdate", registration);
|
||||
const onServiceWorkerUpdate = (registration) => {
|
||||
console.log("[RSW] onServiceWorkerUpdate", registration);
|
||||
|
||||
const key = `open${Date.now()}`;
|
||||
const btn = (
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={async () => {
|
||||
if (registration && registration.waiting) {
|
||||
await registration.unregister();
|
||||
// Makes Workbox call skipWaiting()
|
||||
registration.waiting.postMessage({ type: "SKIP_WAITING" });
|
||||
// Once the service worker is unregistered, we can reload the page to let
|
||||
// the browser download a fresh copy of our app (invalidating the cache)
|
||||
window.location.reload();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{i18n.t("general.actions.refresh")}
|
||||
</Button>
|
||||
);
|
||||
notification.open({
|
||||
icon: <AlertOutlined />,
|
||||
message: i18n.t("general.messages.newversiontitle"),
|
||||
description: i18n.t("general.messages.newversionmessage"),
|
||||
duration: 0,
|
||||
btn,
|
||||
key,
|
||||
});
|
||||
};
|
||||
const key = `open${Date.now()}`;
|
||||
const btn = (
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={async () => {
|
||||
if (registration && registration.waiting) {
|
||||
await registration.unregister();
|
||||
// Makes Workbox call skipWaiting()
|
||||
registration.waiting.postMessage({ type: "SKIP_WAITING" });
|
||||
// Once the service worker is unregistered, we can reload the page to let
|
||||
// the browser download a fresh copy of our app (invalidating the cache)
|
||||
window.location.reload();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{i18n.t("general.actions.refresh")}
|
||||
</Button>
|
||||
);
|
||||
notification.open({
|
||||
icon: <AlertOutlined />,
|
||||
message: i18n.t("general.messages.newversiontitle"),
|
||||
description: i18n.t("general.messages.newversionmessage"),
|
||||
duration: 0,
|
||||
btn,
|
||||
key,
|
||||
});
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
console.log("SWR Registering SW...");
|
||||
serviceWorker.register({ onUpdate: onServiceWorkerUpdate });
|
||||
}
|
||||
}, []);
|
||||
|
||||
return <div style={{ display: "none" }}>Service Worker Registration.</div>;
|
||||
}
|
||||
// if (process.env.NODE_ENV === "production") {
|
||||
// console.log("SWR Registering SW...");
|
||||
console.log("Registering Service Worker...");
|
||||
serviceWorker.register({ onUpdate: onServiceWorkerUpdate });
|
||||
// }
|
||||
|
||||
@@ -9,6 +9,7 @@ import { store, persistor } from "./redux/store";
|
||||
import AppContainer from "./App/App.container";
|
||||
import "./index.css";
|
||||
import LoadingSpinner from "./components/loading-spinner/loading-spinner.component";
|
||||
import "./App/registerServiceWorker.component";
|
||||
|
||||
require("dotenv").config();
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ if (process.env.NODE_ENV === "production") {
|
||||
app.use(express.static(path.join(__dirname, "admin/build")));
|
||||
|
||||
app.get("/service-worker.js", (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname, "..", "build", "service-worker.js"));
|
||||
res.sendFile(path.resolve(__dirname, "client/build", "service-worker.js"));
|
||||
});
|
||||
|
||||
app.get("/admin*", function (req, res) {
|
||||
|
||||
Reference in New Issue
Block a user