Skip to content

[LiveComponent] Add keep-alive modifier to polling plugin #2898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

norkunas
Copy link
Contributor

@norkunas norkunas commented Jul 8, 2025

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues Fix #995
License MIT

This is a naive implementation, which I think needs to be discussed.

I think the listener somehow somewhere should be detached when poll disconnects.

And the best solution would be to add it once for all polling, but I don't see how it is doable.

@carsonbot carsonbot added Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed labels Jul 8, 2025
Copy link
Contributor

github-actions bot commented Jul 8, 2025

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
LiveComponent
live_controller.js 120.02 kB / 23.44 kB 120.47 kB0% / 23.51 kB0%

@norkunas
Copy link
Contributor Author

norkunas commented Jul 8, 2025

Oh, livewire keep-alive is a reverse, as @smnandre said in the issue.. How we should name it?

@smnandre
Copy link
Member

smnandre commented Jul 9, 2025

I'm not sure this should be a modifier... so maybe name does not matter :)

@norkunas
Copy link
Contributor Author

I'm not sure this should be a modifier... so maybe name does not matter :)

And if not a modifier, then what it should be?

Comment on lines +57 to +63
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
this.pollingDirector.stopAllPolling();
} else {
this.pollingDirector.startAllPolling();
}
});
Copy link
Member

Choose a reason for hiding this comment

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

We should remove this event listener on controller's disconnect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i know, first let's agree on direction :) as @smnandre disagree about modifier

@smnandre
Copy link
Member

It should be the default behaviour. Not sure i see a valid usage for polls while the tab is in background

@Kocal
Copy link
Member

Kocal commented Jul 11, 2025

Could it be considered as a BC?
IMHO we should make it configurable in 2.x (default to false) with a deprecation message telling that will be unconfigurable and default to true in 3.x. WDYT?

@smnandre
Copy link
Member

To me it's almost a bug if we send requests at fixed interval when the tab is in background or hidden :|

--> https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

Problem will happen on every browser (except if we speak about big interval but then.. what is the point? what feature is provided by this behaviour ?)

@norkunas
Copy link
Contributor Author

Maybe it's a game where something should still happen in background :D but it's ok for me doing this without modifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LiveComponent] in-view and tab-active modifiers for polling
4 participants