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