Skip to content

Commit bbbb389

Browse files
committed
Update FilesChangedOverview.tsx
Hardened the listener for FilesChangedOverview Added more validation for each type. @danial-lxs LMK if I am wrong but from what I looked up, "event.source === window" is not needed since vsCode already handles this. Also, that version (and many other versions) of the check always seems to fail. If you know something I don't pls let me know.
1 parent a9ab507 commit bbbb389

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

webview-ui/src/components/file-changes/FilesChangedOverview.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,39 @@ const FilesChangedOverview: React.FC = () => {
200200
return
201201
}
202202

203+
// Only process known message types to avoid noisy updates
203204
switch (message.type) {
204205
case "filesChanged":
205-
if (message.filesChanged) {
206-
checkInit(message.filesChanged.baseCheckpoint)
207-
updateChangeset(message.filesChanged)
208-
} else {
209-
// Clear the changeset
210-
setChangeset(null)
206+
// Additional validation for filesChanged message shape
207+
if ("filesChanged" in message) {
208+
if (
209+
message.filesChanged &&
210+
typeof message.filesChanged === "object" &&
211+
typeof message.filesChanged.baseCheckpoint === "string" &&
212+
Array.isArray(message.filesChanged.files)
213+
) {
214+
checkInit(message.filesChanged.baseCheckpoint)
215+
updateChangeset(message.filesChanged)
216+
} else if (message.filesChanged === null || message.filesChanged === undefined) {
217+
// Clear the changeset
218+
setChangeset(null)
219+
}
211220
}
212221
break
213222
case "checkpoint":
214-
handleCheckpointCreated(message.checkpoint, message.previousCheckpoint)
223+
// Additional validation for checkpoint message shape
224+
if (
225+
typeof message.checkpoint === "string" &&
226+
(message.previousCheckpoint === undefined || typeof message.previousCheckpoint === "string")
227+
) {
228+
handleCheckpointCreated(message.checkpoint, message.previousCheckpoint)
229+
}
215230
break
216231
case "checkpointRestored":
217-
handleCheckpointRestored(message.checkpoint)
232+
// Additional validation for checkpointRestored message shape
233+
if (typeof message.checkpoint === "string") {
234+
handleCheckpointRestored(message.checkpoint)
235+
}
218236
break
219237
}
220238
}

0 commit comments

Comments
 (0)