Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(ScheduleFinderLive): use visibilitychange (closes #3125)#3144

Merged
thecristen merged 2 commits intomainmbta/dotcom:mainfrom
cbj/visibilitymbta/dotcom:cbj/visibilityCopy head branch name to clipboard
Apr 29, 2026
Merged

feat(ScheduleFinderLive): use visibilitychange (closes #3125)#3144
thecristen merged 2 commits intomainmbta/dotcom:mainfrom
cbj/visibilitymbta/dotcom:cbj/visibilityCopy head branch name to clipboard

Conversation

@thecristen
Copy link
Copy Markdown
Collaborator

Scope

Builds off prior art:

Implementation

  • Basically rewrites the JS logic into a Phoenix client hook.
    • On component mount, assigns the visibilitychange event listener. It pushes the document visibilityState to the server, which can be handled in the parent LiveView via handle_event.
    • On mount also immediately sends the current visibilityState
    • Reconnections also trigger immediately sending the current visibilityState
    • On component destroyed() we remove the event listener.

Then I edited the Schedule Finder to respond to the changed value:

  • Toggles a new assign, :should_refresh?, which if true will schedule (ahem) the next upcoming departure update.

How to test

I put an IO.inspect() in assign_upcoming_departures/1 to see how frequently it's being called after changing the tab visibility state! I'll note it's not a perfect/immediate transition - for example, if the next upcoming departure update is already queued when the tab changes to a hidden state, that next update will still happen.

@thecristen thecristen requested a review from a team as a code owner April 29, 2026 15:25
@thecristen thecristen requested a review from lvachon1 April 29, 2026 15:25
Comment thread lib/dotcom_web/live/schedule_finder_live.ex
Copy link
Copy Markdown
Contributor

@lvachon1 lvachon1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks for taking my half-baked idea over the line.

@thecristen thecristen enabled auto-merge (squash) April 29, 2026 15:51
@thecristen thecristen merged commit 6b66cdb into main Apr 29, 2026
52 of 54 checks passed
@thecristen thecristen deleted the cbj/visibility branch April 29, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.