From 8d762261d422da44125e3cbded0ace35f6b3cb2e Mon Sep 17 00:00:00 2001
From: mahdahar <89adham@gmail.com>
Date: Mon, 16 Feb 2026 10:52:49 +0700
Subject: [PATCH] Remove all Alpine.js calls to fix memory leaks
- Replace reactive watchers with explicit method calls
- Add setFilterKey() and setFilterTable() methods for manual updates
- Update sort(), nextPage(), prevPage() to trigger computations
- Update templates to use new setter methods
- Compute derived data explicitly after data loading
---
app/Views/shared/content_requests.php | 16 +++----
app/Views/shared/content_validation.php | 2 +-
app/Views/shared/script_requests.php | 58 +++++++++++++------------
app/Views/shared/script_validation.php | 56 +++++++++++-------------
4 files changed, 64 insertions(+), 68 deletions(-)
diff --git a/app/Views/shared/content_requests.php b/app/Views/shared/content_requests.php
index d198e2a..aeb80e7 100644
--- a/app/Views/shared/content_requests.php
+++ b/app/Views/shared/content_requests.php
@@ -12,35 +12,35 @@
-
-
-
-
-
-
-
diff --git a/app/Views/shared/content_validation.php b/app/Views/shared/content_validation.php
index 334e180..6072d0e 100644
--- a/app/Views/shared/content_validation.php
+++ b/app/Views/shared/content_validation.php
@@ -42,7 +42,7 @@
diff --git a/app/Views/shared/script_requests.php b/app/Views/shared/script_requests.php
index 942e586..926a236 100644
--- a/app/Views/shared/script_requests.php
+++ b/app/Views/shared/script_requests.php
@@ -61,14 +61,39 @@ document.addEventListener('alpine:init', () => {
this.sortCol = col;
this.sortAsc = true;
}
+ this.computeSorted();
+ this.computePaginated();
},
nextPage() {
- if (this.currentPage < this.totalPages) this.currentPage++;
+ if (this.currentPage < this.totalPages) {
+ this.currentPage++;
+ this.computePaginated();
+ }
},
prevPage() {
- if (this.currentPage > 1) this.currentPage--;
+ if (this.currentPage > 1) {
+ this.currentPage--;
+ this.computePaginated();
+ }
+ },
+
+ setFilterKey(key) {
+ this.filterKey = key;
+ this.computeFiltered();
+ this.computeSorted();
+ this.computeTotalPages();
+ this.computePaginated();
+ },
+
+ setFilterTable(value) {
+ this.filterTable = value;
+ this.currentPage = 1;
+ this.computeFiltered();
+ this.computeSorted();
+ this.computeTotalPages();
+ this.computePaginated();
},
// Compute methods - called only when dependencies change
@@ -120,32 +145,6 @@ document.addEventListener('alpine:init', () => {
const defaultPrinter = '= $config[session()->get("userrole")]["sampleDialog"]["defaultPrinter"] ?? "lab" ?>';
this.selectedPrinter = defaultPrinter || 'lab';
- // Watchers for reactive updates
- this.$watch('list', () => {
- this.computeFiltered();
- this.computeValidatedCount();
- });
-
- this.$watch('filterKey', () => this.computeFiltered());
- this.$watch('filterTable', () => {
- this.currentPage = 1;
- this.computeFiltered();
- });
-
- this.$watch('filtered', () => {
- this.computeSorted();
- this.computeTotalPages();
- });
-
- this.$watch('sortCol', () => this.computeSorted());
- this.$watch('sortAsc', () => this.computeSorted());
- this.$watch('sorted', () => this.computePaginated());
- this.$watch('currentPage', () => this.computePaginated());
-
- this.$watch('auditData', () => {
- this.computeAuditEvents();
- });
-
// Initial load only - no auto-refresh
this.fetchList();
},
@@ -175,6 +174,9 @@ document.addEventListener('alpine:init', () => {
let codeB = statusOrder[b.STATS] ?? 0;
return codeA - codeB;
});
+ // Compute derived data after list is loaded
+ this.computeFiltered();
+ this.computeValidatedCount();
}).finally(() => {
this.isLoading = false;
});
diff --git a/app/Views/shared/script_validation.php b/app/Views/shared/script_validation.php
index 92c00be..1163075 100644
--- a/app/Views/shared/script_validation.php
+++ b/app/Views/shared/script_validation.php
@@ -29,14 +29,31 @@ document.addEventListener('alpine:init', () => {
this.sortCol = col;
this.sortAsc = true;
}
+ this.computeUnvalidatedSorted();
+ this.computeUnvalidatedPaginated();
},
nextPage() {
- if (this.currentPage < this.unvalidatedTotalPages) this.currentPage++;
+ if (this.currentPage < this.unvalidatedTotalPages) {
+ this.currentPage++;
+ this.computeUnvalidatedPaginated();
+ }
},
prevPage() {
- if (this.currentPage > 1) this.currentPage--;
+ if (this.currentPage > 1) {
+ this.currentPage--;
+ this.computeUnvalidatedPaginated();
+ }
+ },
+
+ setFilterTable(value) {
+ this.filterTable = value;
+ this.currentPage = 1;
+ this.computeUnvalidatedFiltered();
+ this.computeUnvalidatedSorted();
+ this.computeUnvalidatedTotalPages();
+ this.computeUnvalidatedPaginated();
},
// Compute methods - called only when dependencies change
@@ -82,35 +99,6 @@ document.addEventListener('alpine:init', () => {
this.filter.date1 = this.today;
this.filter.date2 = this.today;
- this.$watch('filterTable', () => {
- this.currentPage = 1;
- });
-
- // Watchers for reactive updates
- this.$watch('unvalidatedList', () => {
- this.computeUnvalidatedFiltered();
- this.computeUnvalidatedCount();
- });
- this.$watch('filterTable', () => {
- this.computeUnvalidatedFiltered();
- });
- this.$watch('unvalidatedFiltered', () => {
- this.computeUnvalidatedSorted();
- this.computeUnvalidatedTotalPages();
- });
- this.$watch('sortCol', () => {
- this.computeUnvalidatedSorted();
- });
- this.$watch('sortAsc', () => {
- this.computeUnvalidatedSorted();
- });
- this.$watch('unvalidatedSorted', () => {
- this.computeUnvalidatedPaginated();
- });
- this.$watch('currentPage', () => {
- this.computeUnvalidatedPaginated();
- });
-
// Initial load only - no auto-refresh
this.fetchUnvalidated();
@@ -137,6 +125,12 @@ document.addEventListener('alpine:init', () => {
headers: { 'Content-Type': 'application/json' },
}).then(res => res.json()).then(data => {
this.unvalidatedList = data.data ?? [];
+ // Compute derived data after list is loaded
+ this.computeUnvalidatedFiltered();
+ this.computeUnvalidatedCount();
+ this.computeUnvalidatedSorted();
+ this.computeUnvalidatedTotalPages();
+ this.computeUnvalidatedPaginated();
}).finally(() => {
this.isLoading = false;
});