Skip to content

Commit

Permalink
feat(dev): add separate env var for disabling navigation hooks (#24097)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Jul 31, 2024
1 parent f0268a1 commit 668b792
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions frontend/src/scenes/PreflightCheck/preflightLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ export const preflightLogic = kea<preflightLogicType>([
return preflight?.is_debug
},
],
disableNavigationHooks: [
(s) => [s.preflight],
(preflight): boolean | undefined => {
return preflight?.dev_disable_navigation_hooks
},
],
}),
listeners(({ values, actions }) => ({
handlePreflightFinished: () => {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/scenes/insights/insightSceneLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const insightSceneLogic = kea<insightSceneLogicType>([
path(['scenes', 'insights', 'insightSceneLogic']),
connect(() => ({
logic: [eventUsageLogic],
values: [teamLogic, ['currentTeam'], sceneLogic, ['activeScene'], preflightLogic, ['isDev']],
values: [teamLogic, ['currentTeam'], sceneLogic, ['activeScene'], preflightLogic, ['disableNavigationHooks']],
})),
actions({
setInsightId: (insightId: InsightShortId) => ({ insightId }),
Expand Down Expand Up @@ -322,8 +322,7 @@ export const insightSceneLogic = kea<insightSceneLogicType>([
return false
}

if (values.isDev) {
// TRICKY: We disable beforeUnload handling in dev, but ONLY for insights
if (values.disableNavigationHooks) {
return false
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,7 @@ export interface PreflightStatus {
buffer_conversion_seconds?: number
object_storage: boolean
public_egress_ip_addresses?: string[]
dev_disable_navigation_hooks?: boolean
}

export enum ItemMode { // todo: consolidate this and dashboardmode
Expand Down
3 changes: 3 additions & 0 deletions posthog/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,6 @@ def add_recorder_js_headers(headers, path, url):
PROXY_BASE_CNAME = get_from_env("PROXY_BASE_CNAME", "")

LOGO_DEV_TOKEN = get_from_env("LOGO_DEV_TOKEN", "")

# disables frontend side navigation hooks to make hot-reload work seamlessly
DEV_DISABLE_NAVIGATION_HOOKS = get_from_env("DEV_DISABLE_NAVIGATION_HOOKS", False, type_cast=bool)
3 changes: 3 additions & 0 deletions posthog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def preflight_check(request: HttpRequest) -> JsonResponse:
if settings.DEBUG or settings.E2E_TESTING:
response["is_debug"] = True

if settings.DEV_DISABLE_NAVIGATION_HOOKS:
response["dev_disable_navigation_hooks"] = True

if request.user.is_authenticated:
response = {
**response,
Expand Down

0 comments on commit 668b792

Please sign in to comment.