FIX: chat channel sort order consistency in sidebar (#30180)

This change creates a shallow copy of the public message channels so we don't change the original array while sorting.

Without this change the publicMessageChannels getter cache gets invalidated and cached again with the sorted channels array instead, which causes a bug where the sidebar channel list sorting order is updated by activity when user interacts with the chat drawer.
This commit is contained in:
David Battersby 2024-12-09 15:36:41 +04:00 committed by GitHub
parent acc180611f
commit f0ea57e30e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 6 deletions

View File

@ -34,9 +34,7 @@ export default class ChannelsListPublic extends Component {
}
get channelList() {
return this.args.sortByActivity === true
? this.chatChannelsManager.publicMessageChannelsByActivity
: this.chatChannelsManager.publicMessageChannels;
return this.chatChannelsManager.publicMessageChannelsByActivity;
}
@action

View File

@ -22,7 +22,7 @@ export default class ChatDrawerRoutesChannels extends Component {
{{#if this.chatStateManager.isDrawerExpanded}}
<div class="chat-drawer-content">
<ChannelsListPublic @sortByActivity={{true}} />
<ChannelsListPublic />
</div>
<ChatFooter />

View File

@ -17,7 +17,7 @@ export default class ChatRoutesChannels extends Component {
</navbar.Actions>
</Navbar>
<ChannelsListPublic @sortByActivity={{true}} />
<ChannelsListPublic />
</div>
</template>
}

View File

@ -136,7 +136,7 @@ export default class ChatChannelsManager extends Service {
}
get publicMessageChannelsByActivity() {
return this.#sortChannelsByActivity(this.publicMessageChannels);
return this.#sortChannelsByActivity([...this.publicMessageChannels]);
}
@cached

View File

@ -4,6 +4,7 @@ RSpec.describe "List channels | sidebar", type: :system do
fab!(:current_user) { Fabricate(:user) }
let(:chat) { PageObjects::Pages::Chat.new }
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
before do
chat_system_bootstrap
@ -72,6 +73,24 @@ RSpec.describe "List channels | sidebar", type: :system do
".channel-#{channel_1.id}",
)
end
it "does not change sorting order when using drawer" do
Fabricate(:chat_message, chat_channel: channel_1)
visit("/")
expect(page.find("#sidebar-section-content-chat-channels li:nth-child(1)")).to have_css(
".channel-#{channel_2.id}",
)
drawer_page.visit_index
drawer_page.click_channels
expect(drawer_page).to have_channel_at_position(channel_1, 1)
expect(page.find("#sidebar-section-content-chat-channels li:nth-child(1)")).to have_css(
".channel-#{channel_2.id}",
)
end
end
context "when direct message channels" do