File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,12 @@ class MainWindow {
140
140
return { action : "deny" } ;
141
141
} ) ;
142
142
143
+ // We're intentially preventing the browser from handling unload events (e.g. close, refresh)
144
+ // so we have to handle closing the window manually.
145
+ this . window . on ( "close" , ( ) => {
146
+ this . window ?. destroy ( ) ;
147
+ } ) ;
148
+
143
149
this . window . on ( "closed" , ( ) => {
144
150
this . window = null ;
145
151
const [ promise , resolve ] = PromiseUtils . split < BrowserWindow > ( ) ;
Original file line number Diff line number Diff line change 1
1
import { ChakraProvider } from "@chakra-ui/react" ;
2
2
import { AppProps } from "next/app" ;
3
3
import Head from "next/head" ;
4
+ import { useEffect } from "react" ;
4
5
import { useIsClient } from "usehooks-ts" ;
5
6
6
7
import { ErrorBoundary } from "@/components/ErrorBoundary/ErrorBoundary" ;
@@ -51,6 +52,17 @@ const systemColorModeManager = new SystemColorModeManager();
51
52
export default function MyApp ( { Component, pageProps } : AppProps ) {
52
53
const isClient = useIsClient ( ) ;
53
54
55
+ useEffect ( ( ) => {
56
+ // Prevent window from unloading (i.e. closing or being reloaded). This is due to dynamic routes not
57
+ // being statically generated, which causes the app to 404 if the user reloads on a dynamic route.
58
+ // Closing the window is handled by the main process, which listens for the "close" event and destroys
59
+ // the window.
60
+ window . addEventListener ( "beforeunload" , ( e ) => {
61
+ e . preventDefault ( ) ;
62
+ e . returnValue = true ;
63
+ } ) ;
64
+ } , [ ] ) ;
65
+
54
66
if ( ! isClient ) {
55
67
return null ;
56
68
}
You can’t perform that action at this time.
0 commit comments