Commit 29e5c64
committed
Resolves #4178 ([FR-1401](https://lablup.atlassian.net/browse/FR-1401))
## Problem
The `useDeferredQueryParams` hook was experiencing a state persistence issue where query parameters set on one page would unexpectedly remain when navigating to another page. This occurred because the global `queryParamsAtom` was shared across all pages without proper cleanup mechanisms.
## Root Cause
- The hook used a global atom (`queryParamsAtom`) to store query parameters
- No cleanup logic existed when components unmounted
- Parameters from previous pages would persist in the global state and affect newly mounted components
## Solution Implemented
Implemented a reference counting mechanism to properly manage shared query parameter keys:
- Added `paramRefCountMap` to track how many components are using each parameter key
- Increment reference count when components mount
- Decrement on unmount and only clean up when the last component using a key unmounts
- This preserves the URL as the Single Source of Truth while preventing state leakage between pages
## Impact
- Fixes unexpected state persistence across page navigation
- Maintains proper state isolation between different pages
- Preserves correct behavior when multiple components share the same query parameter keys
[FR-1401]: https://lablup.atlassian.net/browse/FR-1401?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 3dd6515 commit 29e5c64
1 file changed
+50
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
45 | 93 | | |
46 | 94 | | |
47 | 95 | | |
| |||
67 | 115 | | |
68 | 116 | | |
69 | 117 | | |
70 | | - | |
| 118 | + | |
71 | 119 | | |
72 | 120 | | |
73 | 121 | | |
74 | | - | |
75 | 122 | | |
76 | 123 | | |
77 | 124 | | |
| |||
0 commit comments