Skip to content

Commit cd43469

Browse files
author
Zoo (VP)
committed
fix(task-organization): guard taskOrganization revision in full-state merges
The dedicated taskOrganizationUpdated handler drops stale revisions, but the full-state merge path spread newRest unconditionally, so a state push assembled before a mutation commit could arrive after the broadcast and regress the webview to an older revision (folder/pin UI flickers back and the next DnD mutation then gets a spurious TASK_ORG/CONFLICT/002). Apply the same revision guard to the taskOrganization field in mergeExtensionState.
1 parent 37607ce commit cd43469

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

‎webview-ui/src/context/ExtensionStateContext.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ export const mergeExtensionState = (prevState: ExtensionState, newState: Partial
191191
rest.clineMessagesSeq = prevState.clineMessagesSeq
192192
}
193193

194+
// Protect taskOrganization from stale state pushes, mirroring the
195+
// revision guard in the taskOrganizationUpdated handler: a full-state
196+
// push assembled before a mutation commit can arrive after the
197+
// broadcast and regress the webview to an older revision.
198+
if (
199+
newState.taskOrganization !== undefined &&
200+
prevState.taskOrganization !== undefined &&
201+
newState.taskOrganization.revision < prevState.taskOrganization.revision
202+
) {
203+
rest.taskOrganization = prevState.taskOrganization
204+
}
205+
194206
// Note that we completely replace the previous apiConfiguration and customSupportPrompts objects
195207
// with new ones since the state that is broadcast is the entire objects so merging is not necessary.
196208
return {

‎webview-ui/src/context/__tests__/ExtensionStateContext.taskOrganization.spec.tsx‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,62 @@ describe("ExtensionStateContext task organization", () => {
102102
expect(JSON.parse(screen.getByTestId("task-organization").textContent!)).toEqual(snapshot)
103103
})
104104

105+
it("applies a newer taskOrganization revision in a full state message", () => {
106+
render(
107+
<ExtensionStateContextProvider>
108+
<TaskOrganizationTestComponent />
109+
</ExtensionStateContextProvider>,
110+
)
111+
112+
act(() => {
113+
window.dispatchEvent(
114+
new MessageEvent("message", {
115+
data: { type: "state", state: { taskOrganization: makeSnapshot(1) } },
116+
}),
117+
)
118+
})
119+
120+
const next = makeSnapshot(2)
121+
122+
act(() => {
123+
window.dispatchEvent(
124+
new MessageEvent("message", {
125+
data: { type: "state", state: { taskOrganization: next } },
126+
}),
127+
)
128+
})
129+
130+
expect(JSON.parse(screen.getByTestId("task-organization").textContent!)).toEqual(next)
131+
})
132+
133+
it("ignores a stale taskOrganization revision in a full state message", () => {
134+
render(
135+
<ExtensionStateContextProvider>
136+
<TaskOrganizationTestComponent />
137+
</ExtensionStateContextProvider>,
138+
)
139+
140+
act(() => {
141+
window.dispatchEvent(
142+
new MessageEvent("message", {
143+
data: { type: "state", state: { taskOrganization: makeSnapshot(2) } },
144+
}),
145+
)
146+
})
147+
148+
// A full-state push assembled before the revision-2 commit arrives late
149+
// and must not regress the webview to the older revision.
150+
act(() => {
151+
window.dispatchEvent(
152+
new MessageEvent("message", {
153+
data: { type: "state", state: { taskOrganization: makeSnapshot(1) } },
154+
}),
155+
)
156+
})
157+
158+
expect(JSON.parse(screen.getByTestId("task-organization").textContent!)).toEqual(makeSnapshot(2))
159+
})
160+
105161
it("updates task organization on taskOrganizationUpdated with a greater revision", () => {
106162
render(
107163
<ExtensionStateContextProvider>

0 commit comments

Comments
 (0)