rita-workspace 0.5.11 → 0.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -579,11 +579,33 @@ function WorkspaceProvider({ children, lang = "en" }) {
579
579
  }
580
580
  };
581
581
  window.addEventListener("storage", onStorage);
582
- const intervalId = setInterval(recheckConflict, 5e3);
582
+ let intervalId = null;
583
+ const startPolling = () => {
584
+ if (!intervalId && drawingId) {
585
+ intervalId = setInterval(recheckConflict, 5e3);
586
+ }
587
+ };
588
+ const stopPolling = () => {
589
+ if (intervalId) {
590
+ clearInterval(intervalId);
591
+ intervalId = null;
592
+ }
593
+ };
594
+ const onVisibilityChange = () => {
595
+ if (document.hidden) {
596
+ stopPolling();
597
+ } else {
598
+ recheckConflict();
599
+ startPolling();
600
+ }
601
+ };
602
+ if (!document.hidden) startPolling();
603
+ document.addEventListener("visibilitychange", onVisibilityChange);
583
604
  return () => {
584
605
  channel?.close();
585
606
  window.removeEventListener("storage", onStorage);
586
- clearInterval(intervalId);
607
+ document.removeEventListener("visibilitychange", onVisibilityChange);
608
+ stopPolling();
587
609
  };
588
610
  }, [activeDrawing?.id]);
589
611
  (0, import_react.useEffect)(() => {
package/dist/index.mjs CHANGED
@@ -511,11 +511,33 @@ function WorkspaceProvider({ children, lang = "en" }) {
511
511
  }
512
512
  };
513
513
  window.addEventListener("storage", onStorage);
514
- const intervalId = setInterval(recheckConflict, 5e3);
514
+ let intervalId = null;
515
+ const startPolling = () => {
516
+ if (!intervalId && drawingId) {
517
+ intervalId = setInterval(recheckConflict, 5e3);
518
+ }
519
+ };
520
+ const stopPolling = () => {
521
+ if (intervalId) {
522
+ clearInterval(intervalId);
523
+ intervalId = null;
524
+ }
525
+ };
526
+ const onVisibilityChange = () => {
527
+ if (document.hidden) {
528
+ stopPolling();
529
+ } else {
530
+ recheckConflict();
531
+ startPolling();
532
+ }
533
+ };
534
+ if (!document.hidden) startPolling();
535
+ document.addEventListener("visibilitychange", onVisibilityChange);
515
536
  return () => {
516
537
  channel?.close();
517
538
  window.removeEventListener("storage", onStorage);
518
- clearInterval(intervalId);
539
+ document.removeEventListener("visibilitychange", onVisibilityChange);
540
+ stopPolling();
519
541
  };
520
542
  }, [activeDrawing?.id]);
521
543
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rita-workspace",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "description": "Multi-drawing workspace feature for Rita (Excalidraw fork)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",