From 6e35286051a8c7294c5fc82bb73da01caccef428 Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Fri, 13 Aug 2021 15:57:03 -0400 Subject: [PATCH] [MM-33600, MM-34679] Apps commands invalidate form cache (#5333) * invalidate parser form cache on channel navigate and when changing commands * lint Co-authored-by: Mattermod --- .../app_command_parser/app_command_parser.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/components/autocomplete/slash_suggestion/app_command_parser/app_command_parser.ts b/app/components/autocomplete/slash_suggestion/app_command_parser/app_command_parser.ts index 5a577aff8..8a6ca9a88 100644 --- a/app/components/autocomplete/slash_suggestion/app_command_parser/app_command_parser.ts +++ b/app/components/autocomplete/slash_suggestion/app_command_parser/app_command_parser.ts @@ -912,6 +912,9 @@ export class AppCommandParser { } setChannelContext = (channelID: string, rootPostID?: string) => { + if (this.channelID !== channelID || this.rootPostID !== rootPostID) { + this.forms = {}; + } this.channelID = channelID; this.rootPostID = rootPostID; } @@ -1000,14 +1003,17 @@ export class AppCommandParser { } getForm = async (location: string, binding: AppBinding): Promise<{form?: AppForm; error?: string} | undefined> => { - const form = this.forms[location]; + const rootID = this.rootPostID || ''; + const key = `${this.channelID}-${rootID}-${location}`; + const form = this.forms[key]; if (form) { return {form}; } + this.forms = {}; const fetched = await this.fetchForm(binding); if (fetched?.form) { - this.forms[location] = fetched.form; + this.forms[key] = fetched.form; } return fetched; }