Skip to content

Commit

Permalink
Merge pull request #2221 from AdaptiveConsulting/chore/update-modal-r…
Browse files Browse the repository at this point in the history
…ender

Chore/update modal render
  • Loading branch information
algreasley authored Jun 21, 2023
2 parents 7b3c00b + 4b3ed6c commit 52b153f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function initApp() {

const container = document.getElementById("root")
const root = createRoot(container as HTMLElement)

root.render(
<StrictMode>
<GlobalStyle />
Expand Down
9 changes: 6 additions & 3 deletions src/client/src/Web/cacheUpdateModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactDOM from "react-dom"
import { createRoot } from "react-dom/client"
import styled from "styled-components"

import { Modal } from "@/components/Modal"
Expand Down Expand Up @@ -28,7 +28,11 @@ export const showCacheUpdateModal = () => {
const updateRoot = document.createElement("div")
document.body.appendChild(updateRoot)

ReactDOM.render(
const root = createRoot(updateRoot)

console.log("Showing service worker modal")

root.render(
<ThemeProvider>
<Modal title="New updates are available" shouldShow>
<p>Reload the page to see them.</p>
Expand All @@ -47,6 +51,5 @@ export const showCacheUpdateModal = () => {
</Buttons>
</Modal>
</ThemeProvider>,
updateRoot,
)
}
4 changes: 4 additions & 0 deletions src/client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export const getMainApp: () => React.FC = () => {
// could be a disaster
// Wait for our async chunks to be loaded, then skip waiting phase and show
// the user a modal informing them that there are new updates available

console.log("Service worker on update")

Promise.all([
AnalyticsCoreDeferred,
LiveRatesCoreDeferred,
TradesCoreDeferred,
]).then(() => {
console.log("Deferred components resolved, sending skip message")
registration.waiting?.postMessage({ type: "SKIP_WAITING" })
showCacheUpdateModal()
})
Expand Down

0 comments on commit 52b153f

Please sign in to comment.