NgRx Store DevTools filter option in v15.0.0: should it also suppress persistence to localStorage?
0 reputation · 20 Jan 2024, 12:04 UTC
0 reputation · 20 Jan 2024, 12:04 UTC
Goal: decide whether the NgRx Store DevTools filter option introduced in v15.0.0 should also prevent filtered actions from being persisted to the localStorage key used by the DevTools monitor.
Currently the filter only suppresses runtime UI updates and associated console alerts, while actions that match the filter continue to be written to localStorage, which can still accumulate noise in larger applications.
Uncertainty remains about the impact on debugging workflows, storage consumption, and whether existing persisted logs should be migrated or cleared when a filter is applied.
Questions: Should the filter option also block filtered actions from being stored in localStorage? If so, how should the implementation handle already‑persisted entries? What trade‑offs exist between reducing runtime noise and reducing persistence noise?
35275 reputation · 20 Jan 2024, 14:14 UTC
No, the NgRx Store DevTools filter should not suppress persistence to localStorage. The filter is a presentation-layer tool designed to reduce UI noise in the Redux DevTools extension; it is not a middleware or a dispatch interceptor. Because persistence typically occurs via meta-reducers or effects within the NgRx Store cycle, the filter has no architectural authority to block those side effects.
In NgRx v15.0.0, the DevTools filter operates at the boundary between the Store and the browser extension. When an action is filtered, it is simply omitted from the DevTools timeline and console alerts. However, the action has already been successfully dispatched through the Store's pipeline.
Persistence to localStorage (often implemented via ngrx-store-localstorage or custom meta-reducers) happens during the state transition phase. Since the filter is applied after the state has been updated and the action has been processed by the Store, the persistence logic remains unaware of the filter settings. Attempting to link the two would conflate debugging visibility with application state logic.
If the goal is to prevent specific actions from being persisted, you should implement a persistence filter within your meta-reducer or persistence configuration, rather than relying on the DevTools UI filter.
sync` or exclude options in your persistence library) to ignore those action types.localStorage.clear() is required, as the Store cannot retroactively "un-persist" data based on a new DevTools filter setting.To confirm this behavior in your environment:
# 1. Apply a filter in DevTools for action 'USER_PING'
# 2. Trigger the 'USER_PING' action in the app
# 3. Open Browser DevTools > Application > Local Storage
# 4. Observe that the state updated despite the action being hidden in the DevTools timeline.
Missing Diagnostic: Are you using a third-party persistence library (like ngrx-store-localstorage) or a custom meta-reducer for your localStorage logic?
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 20 Jan 2024, 19:34 UTC
The DevTools filter option is a *presentation* toggle. It runs after the Store has processed the action, so the action is already part of the state transition and any persistence meta‑reducer has executed. Consequently, filtered actions still reach the localStorage key that the DevTools monitor uses for replay.
persistFilter option in your Store DevTools setup so developers can opt‑in to blocking persistence independently of UI filtering.Changing the filter after a session has started should not silently rewrite the existing log. Instead, consider
ngrx_store_v15) to preserve old data.
clearPersistedLogs action that developers can dispatch when they want a fresh start.
Mixing display filtering with persistence changes the semantics of the action stream. Time‑travel debugging, export, and post‑mortem analysis rely on a complete, unmodified history. Keeping the two concerns orthogonal avoids subtle bugs when replaying actions or generating bug reports.