Skip to content

Commit

Permalink
fix: Issue with cached logic not triggering aftermount
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Dec 5, 2023
1 parent becc512 commit 69265cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 9 additions & 0 deletions frontend/src/scenes/notebooks/NotebookScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 })
)
Expand All @@ -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 <NotFound object="notebook" />
}
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/scenes/notebooks/notebookSceneLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -44,9 +44,7 @@ export const notebookSceneLogic = kea<notebookSceneLogicType>([
})),

afterMount(({ actions, props }) => {
if (props.shortId === 'new') {
actions.createNotebook(NotebookTarget.Scene)
} else {
if (props.shortId !== 'new') {
actions.loadNotebook()
}
}),
Expand Down

0 comments on commit 69265cc

Please sign in to comment.