From 69265ccec1d6fa5bf887af7ffe5a0aa987199e78 Mon Sep 17 00:00:00 2001 From: Ben White Date: Tue, 5 Dec 2023 10:03:20 +0100 Subject: [PATCH] fix: Issue with cached logic not triggering aftermount --- frontend/src/scenes/notebooks/NotebookScene.tsx | 9 +++++++++ frontend/src/scenes/notebooks/notebookSceneLogic.ts | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/scenes/notebooks/NotebookScene.tsx b/frontend/src/scenes/notebooks/NotebookScene.tsx index 0d0b2baa69f5e..3e9c132b69c6c 100644 --- a/frontend/src/scenes/notebooks/NotebookScene.tsx +++ b/frontend/src/scenes/notebooks/NotebookScene.tsx @@ -7,6 +7,7 @@ import { NotFound } from 'lib/components/NotFound' import { UserActivityIndicator } from 'lib/components/UserActivityIndicator/UserActivityIndicator' import { FEATURE_FLAGS } from 'lib/constants' import { featureFlagLogic } from 'lib/logic/featureFlagLogic' +import { useEffect } from 'react' import { SceneExport } from 'scenes/sceneTypes' import { NotebookTarget } from '~/types' @@ -34,6 +35,7 @@ export const scene: SceneExport = { export function NotebookScene(): JSX.Element { const { notebookId, loading } = useValues(notebookSceneLogic) + const { createNotebook } = useActions(notebookSceneLogic) const { notebook, conflictWarningVisible } = useValues( notebookLogic({ shortId: notebookId, target: NotebookTarget.Scene }) ) @@ -43,6 +45,13 @@ export function NotebookScene(): JSX.Element { const { featureFlags } = useValues(featureFlagLogic) const buttonSize = featureFlags[FEATURE_FLAGS.POSTHOG_3000] ? 'small' : 'medium' + useEffect(() => { + if (notebookId === 'new') { + // NOTE: We don't do this in the logic afterMount as the logic can get cached by the router + createNotebook(NotebookTarget.Scene) + } + }, [notebookId]) + if (!notebook && !loading && !conflictWarningVisible) { return } diff --git a/frontend/src/scenes/notebooks/notebookSceneLogic.ts b/frontend/src/scenes/notebooks/notebookSceneLogic.ts index 8d71c0f9f93db..19061b7208bea 100644 --- a/frontend/src/scenes/notebooks/notebookSceneLogic.ts +++ b/frontend/src/scenes/notebooks/notebookSceneLogic.ts @@ -3,7 +3,7 @@ import { Scene } from 'scenes/sceneTypes' import { urls } from 'scenes/urls' import { notebooksModel } from '~/models/notebooksModel' -import { Breadcrumb, NotebookTarget } from '~/types' +import { Breadcrumb } from '~/types' import { notebookLogic } from './Notebook/notebookLogic' import type { notebookSceneLogicType } from './notebookSceneLogicType' @@ -44,9 +44,7 @@ export const notebookSceneLogic = kea([ })), afterMount(({ actions, props }) => { - if (props.shortId === 'new') { - actions.createNotebook(NotebookTarget.Scene) - } else { + if (props.shortId !== 'new') { actions.loadNotebook() } }),