Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay): dispatch comment bus notifications through a bound action (#81113)

Tue Haulund2056bb32e394
diff --git a/frontend/src/scenes/session-recordings/player/commenting/playerCommentModel.ts b/frontend/src/scenes/session-recordings/player/commenting/playerCommentModel.ts
index 2cfc27855e59..51d1ab00f385 100644
--- a/frontend/src/scenes/session-recordings/player/commenting/playerCommentModel.ts
+++ b/frontend/src/scenes/session-recordings/player/commenting/playerCommentModel.ts
@@ -19,6 +19,11 @@ export type playerCommentModelType = MakeLogicType<{}, playerCommentModelActions
* the currently active player will listen to this
* and can e.g. enter or exit comment mode in response
* it relies on being used when there is always a mounted player with a logic listening for this
+ *
+ * dispatch into it from another logic with connect({ actions: [playerCommentModel, ['commentEdited']] })
+ * or from a component with useActions, so the action creator binds at build time
+ * calling playerCommentModel.actions.x() at runtime resolves through kea's wrapper proxy,
+ * which throws "is not mounted" once the built instance has been evicted from the build cache
*/
export const playerCommentModel = kea<playerCommentModelType>([
path(['scenes', 'session-recordings', 'player', 'playerCommentModel']),
diff --git a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts
index adf7880added..c758ec1c7194 100644
--- a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.test.ts
@@ -13,6 +13,7 @@ import { CommentType } from '~/types'
import { recordingMetaJson } from '../../__mocks__/recording_meta'
import { setupSessionRecordingTest } from '../__mocks__/test-setup'
+import { playerCommentModel } from './playerCommentModel'
import { playerCommentOverlayLogic } from './playerFrameCommentOverlayLogic'
jest.mock('../snapshot-processing/DecompressionWorkerManager')
@@ -90,7 +91,7 @@ describe('playerFrameCommentOverlayLogic', () => {
await expectLogic(logic, () => {
logic.actions.submitRecordingComment()
- }).toDispatchActions(['submitRecordingCommentSuccess'])
+ }).toDispatchActions([playerCommentModel.actionTypes.commentEdited, 'submitRecordingCommentSuccess'])
expect(createSpy).toHaveBeenCalledTimes(1)
expect(createSpy.mock.calls[0][0].item_context).toMatchObject({
diff --git a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts
index 79a741ae2c90..833b0eb214ff 100644
--- a/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/commenting/playerFrameCommentOverlayLogic.ts
@@ -66,6 +66,9 @@ export interface playerCommentOverlayLogicActions {
ensureAllMembersLoaded: () => {
value: true
} // membersLogic
+ commentEdited: (recordingId: string) => {
+ recordingId: string
+ } // playerCommentModel
setIsCommenting: (isCommenting: boolean) => {
isCommenting: boolean
} // sessionRecordingPlayerLogic
@@ -154,9 +157,15 @@ export const playerCommentOverlayLogic = kea<playerCommentOverlayLogicType>([
props({} as PlayerCommentOverlayLogicProps),
connect((props: PlayerCommentOverlayLogicProps) => ({
values: [sessionRecordingPlayerLogic(props), ['currentPlayerTime', 'currentTimestamp', 'sessionPlayerData']],
- actions: [sessionRecordingPlayerLogic(props), ['setIsCommenting'], membersLogic, ['ensureAllMembersLoaded']],
- // its subscribers listen by actionTypes, which doesn't mount it, so keep the bus alive here
- logic: [playerCommentModel],
+ actions: [
+ sessionRecordingPlayerLogic(props),
+ ['setIsCommenting'],
+ membersLogic,
+ ['ensureAllMembersLoaded'],
+ // bound at build time, so notifying the bus can't depend on it still being mounted
+ playerCommentModel,
+ ['commentEdited'],
+ ],
})),
actions({
editComment: (comment: RecordingCommentForm) => ({ comment }),
@@ -292,7 +301,7 @@ export const playerCommentOverlayLogic = kea<playerCommentOverlayLogicType>([
},
slug: `/replay/${props.recordingId}#panel=discussion`,
})
- playerCommentModel.actions.commentEdited(props.recordingId)
+ actions.commentEdited(props.recordingId)
} catch (e) {
lemonToast.error(`Could not save your comment: ${(e as Error).message}`)
} finally {
@@ -350,7 +359,7 @@ export const playerCommentOverlayLogic = kea<playerCommentOverlayLogicType>([
await api.comments.create({ ...apiPayload, is_task: values.asTask })
}
- playerCommentModel.actions.commentEdited(props.recordingId)
+ actions.commentEdited(props.recordingId)
actions.resetRecordingComment()
actions.setAsTask(false)
actions.setIsCommenting(false)