rea-analysis-optimization
MOmorluto/rea486k8,943 new stars in the last 7 days
Apply Hotwire, Turbo, Stimulus, and ActionCable best practices for real-time Rails interfaces. Use when building Turbo Streams/Frames, Stimulus interactions, or websocket-driven updates.
Use for Turbo/Stimulus/ActionCable architecture and reviews. Patterns from Campfire (cable-heavy chat) and Fizzy (streams-only kanban).
Two proven 37signals topologies:
turbo_stream_from, broadcasts_refreshes + morph, lazy frames with ETags. Default to this for CRUD-ish apps.Rule of thumb: Turbo Streams for anything that changes the DOM; bare ActionCable only for tiny ephemeral signals.
turbo_refreshes_with method: :morph, scroll: :preserve.turbo_frame_tag ..., src:, loading: :lazy and give the frame endpoint its own fresh_when ETag. Extract frequently-changing fragments into their own frames so they don't bust the parent cache.data-turbo-permanent for elements that must survive navigation/morph (footer trays, in-progress editors).turbo:before-morph-attribute + preventDefault().turbo_exempts_page_from_cache); rely on frame-level ETags instead.<template> partial with $placeholder$ tokens; client clones it with a generated ID before submit; the stream response replaces it.Message::Broadcasts concern with broadcast_create), not in controllers.[board.account, :all_boards], [user, :notifications] — stream names are isolation boundaries.broadcasts_refreshes for direct subscribers plus broadcasts_refreshes_to ->(r) { [r.account, :aggregate_view] } for account-wide views.before_update when preview-relevant fields change; broadcast if: :preview_changed?.Model.suppressing_turbo_broadcasts), e.g. around ActiveStorage analysis.render_to_string once, then broadcast_replace_to user, ..., html: per recipient.broadcast_*_later async variants when synchronous broadcasting hurts request latency.broadcast_image_tag pattern) so URLs resolve.?since=<epoch_ms>); server appends new records and replaces updated ones.HeartbeatChannel gives reliable connected/disconnected callbacks for triggering catch-up and a debounced offline UI.connect() with a turbo-preview check so back/forward cache previews don't open sockets or request permissions.disconnect. For cable subscriptions, defer unsubscribe one animation frame and skip if the element reconnected (morph churn).data-controller/data-action/target wiring in Ruby helpers (message_area_tag) so views stay declarative and the contract lives in one place.<meta> tags into a tiny window.Current object rather than inlining JSON.targetConnected callbacks).maintain_scroll: true) on broadcasts and handle it once in a turbo:before-stream-render listener.id on turbo:submit-start so background broadcasts can't race the form's own stream response.Connection#connect with the same identity resolution as HTTP; scope channel subscriptions through ownership (current_user.rooms.find_by(id: params[:room_id])).ActionCable.server.remote_connections.where(current_user: user).disconnect.connections counter + connected_at, 60s freshness scope) to survive multi-tab and reconnects; debounce visibility changes (~5s) to avoid flicker.request.script_name via a custom meta tag helper.touch: true chains so child edits invalidate parents.data-creator-id, let a Stimulus controller compare against Current.user and toggle visibility — don't break fragment caching for per-user toggles.assert_turbo_stream_broadcasts([user, :notifications], count: 1) { ... } and assert_no_turbo_stream_broadcasts for negatives.as: :turbo_stream + assert_turbo_stream action: :replace, target: dom_id(...).ActionCable.server.pubsub.broadcasts + assert_select covers it.using_session("OtherUser") for multi-user realtime, and wait for turbo-cable-stream-source[connected] before asserting.turbo_stream_from already does.data-turbo-permanent).MOmorluto/rea486k8,943 new stars in the last 7 days
Diagnose hard bugs and performance regressions by building a feedback loop with tests or scripts.
MAmattpocock/skills337k4,978 new stars in the last 7 days
MAmattpocock/skills337k4,978 new stars in the last 7 days
MAmattpocock/skills337k4,978 new stars in the last 7 days
MAmattpocock/skills337k4,978 new stars in the last 7 days
MAmattpocock/skills337k4,978 new stars in the last 7 days