FIX: user autocomplete search cache pollution #34208
Merged
+125
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current chat autocomplete pipeline can mutate the user object selected for autocomplete here:
discourse/plugins/chat/assets/javascripts/discourse/components/chat-composer.gjs
Line 485 in 071e821
Specifically this occurs when we attempt to create a record in the store service where it already exists, and the logic for fetching the right record there deletes some properties from the input object:
discourse/app/assets/javascripts/discourse/app/services/store.js
Lines 426 to 435 in 216df43
This mutates the object that is eventually used to replace the search term (and therefore causes an error as it is now missing all its properties except for
id
). This also pollutes the upstream cache in the userSearch JS module.This PR fixes both issues by cloning the user objects before they get passed into the processing functions.