PERF: defer loading channels (#26155)

Prior to this change we would pre-load all the user channels which making initial page load slower. This change will make them be loaded right after initial load. In the past this was not possible as the channels would have to be loaded on each page transition. However since about a year, we made the channels to be cached on the frontend and no other request will be needed.

I have decided for now to not show a loading state in the sidebar as I think it would be noise, but we can reconsider this later.

Note given we don't have the channels loaded at first certain things where harder to accomplish. The biggest UX change of this commit is that we removed all the complex logic of computing the best channel to display when you load /chat. We will now store the id of the last channel you visited and will use this id to decide which channel to show.
This commit is contained in:
Joffrey JAFFEUX
2024-03-18 08:35:07 +01:00
committed by GitHub
parent 0bccdc4dbc
commit bbb8595107
28 changed files with 391 additions and 877 deletions

View File

@ -18,6 +18,7 @@ RSpec.describe "Navigation", type: :system do
let(:chat_drawer_page) { PageObjects::Pages::ChatDrawer.new }
before do
current_user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => category_channel.id)
chat_system_bootstrap(current_user, [category_channel, category_channel_2])
current_user.user_option.update(
chat_separate_sidebar_mode: UserOption.chat_separate_sidebar_modes[:never],
@ -83,13 +84,11 @@ RSpec.describe "Navigation", type: :system do
expect(page).to have_current_path(
chat.channel_path(category_channel.slug, category_channel.id),
)
expect(page).to have_css("html.has-full-page-chat")
expect(page).to have_css(".chat-message-container[data-id='#{message.id}']")
end
end
context "when visiting mobile only routes on desktop" do
it "redirects /chat/channels to ideal first channel" do
it "redirects /chat/channels to browse" do
visit("/chat/channels")
expect(page).to have_current_path(
@ -97,7 +96,7 @@ RSpec.describe "Navigation", type: :system do
)
end
it "redirects /chat/direct-messages to ideal first channel" do
it "redirects /chat/direct-messages to browse" do
visit("/chat/direct-messages")
expect(page).to have_current_path(
@ -153,7 +152,9 @@ RSpec.describe "Navigation", type: :system do
chat_page.open
chat_page.minimize_full_page
expect(page).to have_current_path(latest_path)
expect(page).to have_current_path(
chat.channel_path(category_channel.slug, category_channel.id),
)
end
end