diff --git a/src/LiveComponent/CHANGELOG.md b/src/LiveComponent/CHANGELOG.md index 84ed16c82dc..04b9a967a20 100644 --- a/src/LiveComponent/CHANGELOG.md +++ b/src/LiveComponent/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 2.28.0 + +- Add `keep-alive` modifier to polling plugin + ## 2.27.0 - Add events assertions in `InteractsWithLiveComponents`: diff --git a/src/LiveComponent/assets/dist/live_controller.js b/src/LiveComponent/assets/dist/live_controller.js index 4902665e1de..4541b631c4c 100644 --- a/src/LiveComponent/assets/dist/live_controller.js +++ b/src/LiveComponent/assets/dist/live_controller.js @@ -2732,6 +2732,16 @@ class PollingPlugin { duration = Number.parseInt(modifier.value); } break; + case 'keep-alive': + document.addEventListener('visibilitychange', () => { + if (document.hidden) { + this.pollingDirector.stopAllPolling(); + } + else { + this.pollingDirector.startAllPolling(); + } + }); + break; default: console.warn(`Unknown modifier "${modifier.name}" in data-poll "${rawPollConfig}".`); } diff --git a/src/LiveComponent/assets/src/Component/plugins/PollingPlugin.ts b/src/LiveComponent/assets/src/Component/plugins/PollingPlugin.ts index 8a22cabefb3..e0cd4f89746 100644 --- a/src/LiveComponent/assets/src/Component/plugins/PollingPlugin.ts +++ b/src/LiveComponent/assets/src/Component/plugins/PollingPlugin.ts @@ -52,6 +52,16 @@ export default class implements PluginInterface { duration = Number.parseInt(modifier.value); } + break; + case 'keep-alive': + document.addEventListener('visibilitychange', () => { + if (document.hidden) { + this.pollingDirector.stopAllPolling(); + } else { + this.pollingDirector.startAllPolling(); + } + }); + break; default: console.warn(`Unknown modifier "${modifier.name}" in data-poll "${rawPollConfig}".`);