[LiveComponent] Enhance polling with limit, visible modifiers and dynamic PHP control#3365
Open
xDeSwa wants to merge 1 commit intosymfony:2.xfrom
Open
[LiveComponent] Enhance polling with limit, visible modifiers and dynamic PHP control#3365xDeSwa wants to merge 1 commit intosymfony:2.xfrom
xDeSwa wants to merge 1 commit intosymfony:2.xfrom
Conversation
Contributor
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
|||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ Description
This PR introduces lightweight yet powerful controls for the
data-pollfeature to prevent over-fetching, save server resources, and give developers fine-grained control over polling loops.While I noticed that PR #2965 proposes a very comprehensive and detailed polling overhaul, I believe this PR covers the most immediate and highly requested polling needs in a simpler, highly stable, and backward-compatible way. (I am completely open to adapting this approach, changing modifier names, or merging efforts based on your feedback!).
✨ New Features
limit(n)Modifier: Stops the polling loop after exactlynsuccessful requests. The counter is securely stored in memory across component re-renders, preventing the limit from infinitely resetting itself.visible&visible(page)Modifiers: Inspired by the visibility discussions in PR [LiveComponent] Addkeep-alivemodifier to polling plugin #2898.visible(orvisible(component)): UsesIntersectionObserverto automatically pause polling when the component leaves the viewport.visible(page): Pauses polling only when the browser tab is backgrounded/hidden.limitcounter; it resumes exactly where it left off. Default behavior (without these modifiers) remains unchanged for strict BC.stopPoll): AddedstopPoll(string $actionName = '$render')andstopAllPolls()toComponentToolsTrait. This allows developers to stop frontend polling dynamically from PHP. For example, stopping a progress bar poll precisely when a long-running promotional product import finishes.🛠️ Architecture & Stability Improvements
destroy()cleanup method toPollingDirectorthat removes global event listeners and disconnects observers when the LiveComponent is disconnected.setIntervalto a safe recursive pattern to prevent overlapping requests (DDoS effect) if the server responds slower than the defined polling delay.Looking forward to your thoughts and suggestions!