Repository navigation
Carry the message menu once per room instead of in every message - #357
namespaceMarcello wants to merge 2 commits into
Conversation
A message is rendered with its options menu inside it: eight quick boost forms, new boost, reply, copy link and edit. The menu is about two thirds of the message's HTML and is the same for every message but for the message's id, yet it travels with each one: in the room page, in every page of older messages, and in the frame that Action Cable encodes and writes once per person in the room for each new message. A message now carries the button alone. The room page carries the menu once, as a template with $messageId$ where the id goes, and the messages controller copies it into a message the first time its menu is opened, or when arrow up asks for the edit link of the last message. The copy happens on the same toggle that popup#toggle listens to, and before it, because that one measures the menu to place it. A message with a file still renders its own menu: Download and Share point at the file. The cache of rendered menus goes, as what is left of a message's controls is a static button. A copy link is now built by the page it is copied from, so it follows the reader's origin where a broadcast message used to carry the poster's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017uAnU1dboBiJTZ23xmGpPe
There was a problem hiding this comment.
🟡 Changes recommended
Text-message menus are broken on search results and standalone message pages because those views lack the required controller and template.
1 open finding
What changed in this PR
Moves shared message menus to a room-level template, reducing repeated HTML while preserving attachment-specific menus.
Changes:
- Lazily inserts shared menus for text messages.
- Retains inline menus for attachments.
- Updates controller and system coverage.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
app/helpers/messages_helper.rb |
Removes action-menu fragment caching. |
app/javascript/controllers/messages_controller.js |
Instantiates menus from the shared template. |
app/views/messages/_actions.html.erb |
Reduces actions to a button and attachment menu. |
app/views/messages/_actions_menu.html.erb |
Defines reusable menu markup. |
app/views/messages/_actions_menu_template.html.erb |
Provides the room-level template. |
app/views/messages/_message.html.erb |
Removes the copy-link URL argument. |
app/views/rooms/show.html.erb |
Renders the shared menu template. |
test/controllers/fragment_cache_test.rb |
Removes obsolete controls-cache assertions. |
test/controllers/messages/boosts_controller_test.rb |
Tests quick boosts through the template. |
test/controllers/messages_controller_test.rb |
Covers broadcasts, attachments, and origins. |
test/controllers/rooms_controller_test.rb |
Verifies one template per room. |
test/system/message_menu_test.rb |
Covers lazy and attachment menus. |
test/test_helper.rb |
Includes the menu test helper. |
test/test_helpers/message_menu_test_helper.rb |
Builds instantiated menus for assertions. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| <% if message.attachment? %> | ||
| <%= render "messages/actions_menu", message_id: message.id, room: message.room, attachment: message.attachment %> |
There was a problem hiding this comment.
The menu does depend on the room page's controller and template, and those two views have neither. Neither of them puts the button within reach, though, on main or here:
- Search results hide a message's actions altogether:
.searches .message__actions { display: none !important; visibility: hidden !important; }insidebar.css. messages/showis the source of a message's edit frame: the redirect after an update and the editor's close link both load it inside the frame. Opened on its own, the message staysvisibility: hidden, because a message only becomes visible once the messages or the search results controller formats it (.message--formatted), and that page has neither.
So no click gets to an empty <details> there. 10795f5 adds a system test that holds both pages to it: the message is there and its options button can't be reached. It fails if the search rule is removed, or if a message is made visible without being formatted, which is when those pages would need the template too.
Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work.
A message's menu is copied from the template its room page carries, by that page's messages controller. Search results and the page of a single message render messages without either, and rely on the button not being reachable there: search results hide a message's actions, and a message opened on its own is never formatted into view. Hold both pages to that, so that showing the button on either one fails here and points at the template. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017uAnU1dboBiJTZ23xmGpPe
|
A second browser measurement, of gestures rather than of a page load. The description's figures are for a room page opened in a fresh tab, where the gain is small. Switching room, reloading and scrolling back repeat the per-message work without the tab's fixed cost, and there it shows more. Setup. From our machine: a laptop with an AMD Ryzen 9 7940HX, Docker. The production images of
What a switch to a room with a new message costs the main thread:
The server answers the room page in about 30 ms on both images; the difference is the browser's. In this scenario the page has 3,903 elements on What doesn't change: your own message appearing after Enter (11 and 10 ms), the message reaching the other four, typing notices, boosts and the unread dot, all under 120 ms on both. What this does not show. Headless Chrome on Linux, not Safari, Firefox or a real phone: the throttling is an emulation. A local network. Text-only messages. Five repetitions per figure, and one run only for The scenario (Selenium driving the five browsers, a small in-page stopwatch, Chrome's Performance and Profiler domains) can be posted here. Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work. |

Every message is rendered with its options menu inside it: eight quick boost forms, new boost, reply, copy link and edit. On
maina text message is 9,191 bytes of HTML and about 5,900 of them are that menu, the same for every message but for the message's id. It travels with each message: in the room page, in every page of older messages, and in the frame that Action Cable encodes and writes once per person in the room when a message is posted. That last cost is paid once per recipient, so it grows with the room.This makes a message carry the button alone:
messages/_actions.html.erbrenders the<details>and its<summary>. The menu moves tomessages/_actions_menu.html.erb.messages/_actions_menu_template.html.erb: a<script type="text/template">like the one pending messages use, with$messageId$where the id goes.messages_controller.jscopies it into a message the first time its menu is opened. It does so on thetogglethatpopup#togglealready listens to, and ahead of it, because that one measures the menu to place it; this is also why the copy is synchronous rather than a lazily loaded frame. Arrow up, which clicks the edit link of your last message, builds the menu first.cache_message_actionsgoes: what is left of a message's controls is a static button.Once open, the menu is the same markup in the same place as before. Two things do change:
maina message that arrived by broadcast carries the poster's.#350 changes the same partials and
cache_message_actions: it caches the rendering of the menu, where this takes the menu out of the message. Whichever lands second needs a rebase, and this branch will get it if it is the one.Measurements
Counts, from the production image built from
mainat edbc779 and from this branch, a room page with 40 text messages:mainThe template adds 5,863 bytes to the room page, once.
Timings, from our machine: a laptop with an AMD Ryzen 9 7940HX, Docker. The same two production images (Thruster, 3 Puma workers with 5 threads, 3 Resque workers, Redis inside) on 4 CPUs, the database on a Docker volume (ext4), and
loadgen cablefrom basecamp/once-campfire-verification on 4 other CPUs: 1,000 people, each with the room page's subscriptions, in one open room. Median of 3 runs alternatingmainand this PR, lowest and highest in brackets; the paced phase is 30 messages.mainIn a browser the gain is smaller. Headless Chrome on the same machine, loading that room page from each image in turn, 15 loads each, every load in a fresh tab: the main thread is busy 375 ms per load on
main(351–427) and 323 ms with this PR (292–381), the page has 1,379 event listeners against 939 and a JavaScript heap of 7.3 MB against 5.7 MB.DOMContentLoadeddoesn't move (214 and 222 ms).Tests
test/controllers/rooms_controller_test.rb: the room page has a button in every message, no menu in any, and one template; filled in for a message, the template's new boost and edit links point at that message and its frames, and it has Reply and no Download or Share. Onmainit fails on the menus found inside the messages.test/controllers/messages/boosts_controller_test.rb: the quick boost test reads its forms from the template filled in for the message, and still posts one.test/controllers/messages_controller_test.rb: a posted text message is broadcast with its button and no menu (fails onmain); a posted file is broadcast with its own menu, checked link by link (passes onmaintoo); the copy link test now covers the room's template under each origin, and a file's broadcast and regular read as before.test/controllers/fragment_cache_test.rb: the test of the menu cache keeps its other half, the author rendered fresh after a creator edit.test/system/message_menu_test.rb: a quick boost from the menu; a message has no menu until it is opened, gets one placed bypopup#toggleon the first open, and still has one after closing and reopening (fails onmainat the first step); a message with a file opens the menu it came with.Each of these was seen failing with one thing broken at a time: the copy without its guard, the action removed or placed after
popup#toggle, arrow up without the copy, the id left unfilled, each of the three frame ids, the template missing from the page or given the file's buttons, a file's menu dropped, the copy link without its origin.Validation in the container:
bin/rubocop,bin/brakeman,bin/rails herb:check,bin/rails test(582 runs) andbin/rails test:system(30 runs) all pass with no failures.Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work.
🤖 Generated with Claude Code