fix: Remove state_key: null from Seshat search results (#31524)

* fix: Remove state_key: null from Seshat search results

Seshat includes "state_key": null for non-state events, which causes
matrix-js-sdk to incorrectly treat them as state events. This prevents
encrypted messages from rendering properly in search results.

This fix removes the null state_key from search results and context
events before passing them to the SDK.

* test: cover local search null state_key edge cases

* test: satisfy strict types in searching coverage test

---------

Co-authored-by: David Baker <dbkr@users.noreply.github.com>
This commit is contained in:
Hiroshi Shinaoka
2026-02-05 16:19:02 +00:00
committed by GitHub
co-authored by David Baker
parent 1d7fd0b9d3
commit 8de804d0c0
2 changed files with 282 additions and 0 deletions
+20
View File
@@ -175,6 +175,26 @@ async function localSearch(
throw new Error("Local search failed");
}
// Fix state_key: null issue - Seshat includes "state_key": null for non-state events,
// which causes matrix-js-sdk to incorrectly treat them as state events
if (localResult.results) {
for (const searchResult of localResult.results) {
const event = searchResult.result as unknown as Record<string, unknown>;
if (event?.state_key === null) delete event.state_key;
// Also fix context events
if (searchResult.context) {
for (const ctxEvent of searchResult.context.events_before || []) {
const ev = ctxEvent as unknown as Record<string, unknown>;
if (ev?.state_key === null) delete ev.state_key;
}
for (const ctxEvent of searchResult.context.events_after || []) {
const ev = ctxEvent as unknown as Record<string, unknown>;
if (ev?.state_key === null) delete ev.state_key;
}
}
}
}
searchArgs.next_batch = localResult.next_batch;
const result = {