-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
104 lines (94 loc) · 3.18 KB
/
app.js
File metadata and controls
104 lines (94 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Router } from "./router.js";
import { AppState } from "./lib/app_state.js";
import { APP_CONFIG } from "./lib/config.js";
import { App } from "./ui/app.js";
import { buildRoutes } from "./ui/routes.js";
console.log("[App] Initializing application");
const state = new AppState();
const app = new App({ state });
window.appState = state;
window.appInstance = app;
console.log("[App] Creating router");
const router = new Router(
buildRoutes({ app }),
(ctx) => app.renderNotFound({ ...ctx, state }),
{
basePath: APP_CONFIG.basePath,
updateLocation: false,
onRouteChange: (path) => {
app.updateLocationBar(path);
app.updatePaneNav();
},
}
);
app.setRouter(router);
console.log("[App] Starting router");
router.start();
// Track navigation events to debug server requests
window.addEventListener("beforeunload", (e) => {
console.log("[App] beforeunload event fired");
});
window.addEventListener("unload", (e) => {
console.log("[App] unload event fired");
});
window.addEventListener("popstate", (e) => {
console.log("[App] popstate event fired:", e.state);
});
window.addEventListener("hashchange", (e) => {
console.log("[App] hashchange event fired:", e.oldURL, "->", e.newURL);
});
// Monitor for any programmatic navigation
try {
const originalLocationAssign = window.location.assign.bind(window.location);
const originalLocationReplace = window.location.replace.bind(window.location);
const originalLocationReload = window.location.reload.bind(window.location);
try {
Object.defineProperty(window.location, 'assign', {
value: function(...args) {
console.log("[App] window.location.assign() called with:", args);
console.trace("[App] Location assign stack trace");
return originalLocationAssign(...args);
},
writable: true,
configurable: true
});
} catch (e) {
console.warn("[App] Could not override location.assign:", e);
}
try {
Object.defineProperty(window.location, 'replace', {
value: function(...args) {
console.log("[App] window.location.replace() called with:", args);
console.trace("[App] Location replace stack trace");
return originalLocationReplace(...args);
},
writable: true,
configurable: true
});
} catch (e) {
console.warn("[App] Could not override location.replace:", e);
}
try {
Object.defineProperty(window.location, 'reload', {
value: function(...args) {
console.log("[App] window.location.reload() called with:", args);
console.trace("[App] Location reload stack trace");
return originalLocationReload(...args);
},
writable: true,
configurable: true
});
} catch (e) {
console.warn("[App] Could not override location.reload:", e);
}
} catch (e) {
console.warn("[App] Could not set up location monitoring:", e);
}
// Track errors that might cause navigation
window.addEventListener("error", (e) => {
console.error("[App] Global error:", e.error, e.message, e.filename, e.lineno);
});
window.addEventListener("unhandledrejection", (e) => {
console.error("[App] Unhandled promise rejection:", e.reason);
});
console.log("[App] Application initialization complete");