Skip to content

docs and tests: filter out specific actions from being sent to Redux DevTools#3252

Merged
dai-shi merged 14 commits intopmndrs:mainfrom
totorototo:main
Oct 31, 2025
Merged

docs and tests: filter out specific actions from being sent to Redux DevTools#3252
dai-shi merged 14 commits intopmndrs:mainfrom
totorototo:main

Conversation

@totorototo
Copy link
Copy Markdown
Contributor

@totorototo totorototo commented Oct 7, 2025

Add actionsDenylist Documentation and Tests

Summary

This PR adds comprehensive documentation and test coverage for the actionsDenylist option in the Zustand DevTools middleware. This option allows developers to filter out specific actions from Redux DevTools using regex patterns, and is passed directly to Redux DevTools Extension.

Documentation Added

Updated docs/middlewares/devtools.md

Added a comprehensive new section titled "Filtering actions with actionsDenylist" that provides:

API Reference Section

  • Parameter Definition: Documented actionsDenylist as an optional parameter accepting string | string[]
  • Type Details: Explained it accepts regex pattern strings for flexible filtering
  • Behavior Description: Clarified that filtering is handled by Redux DevTools Extension, not by Zustand
  • Integration Notes: Documented how it works seamlessly with other DevTools options like name, store, etc.

Usage Examples

Provided three distinct examples demonstrating different filtering scenarios:

  1. Array Pattern Filtering: Shows how to filter multiple action categories using an array of regex patterns

    • Example: Filtering both internal/.* and secret/.* actions simultaneously
    • Demonstrates how to hide internal implementation details from DevTools
  2. Single Pattern Filtering: Illustrates using a single regex string for simpler cases

    • Example: Using 'secret.*' to hide all secret-related actions
    • Shows cleaner syntax when only one pattern is needed
  3. Real-World Authentication Store: Complete, practical example showing:

    • How to structure action names for effective filtering
    • Filtering internal actions while keeping user-facing actions visible
    • Best practices for organizing action namespaces

Educational Content

  • Use Cases: Explained four primary scenarios for using actionsDenylist:

    • Hiding sensitive operations (passwords, tokens, API keys)
    • Reducing noise from high-frequency actions
    • Filtering debug/development-only actions
    • Focusing on relevant actions during debugging
  • Technical Notes: Added important clarifications:

    • Regex pattern syntax and case-sensitivity
    • How actions are still executed but hidden from display
    • Relationship with Redux DevTools Extension's native filtering

Table of Contents Update

  • Added new entry linking to the filtering section
  • Positioned logically between "Slices pattern" and "Cleanup" sections
  • Maintains documentation flow and discoverability

Usage Example from Documentation

import { create } from 'zustand'
import { devtools } from 'zustand/middleware'

const useStore = create<Store>()(
  devtools(
    (set) => ({
      user: null,
      token: null,
      login: (user, token) => set({ user, token }, undefined, 'auth/login'),
      logout: () => set({ user: null, token: null }, undefined, 'auth/logout'),
      updateData: () => set({ user: 'updated' }, undefined, 'internal/updateData'),
    }),
    {
      name: 'AuthStore',
      actionsDenylist: ['internal/.*'], // Hides all 'internal/*' actions
    },
  ),
)

Tests Added

Updated tests/devtools.test.tsx

Added a dedicated test suite for the actionsDenylist feature to ensure proper functionality and prevent regressions.

Test Suite Structure

Created a new describe block named 'actionsDenylist' containing comprehensive test coverage:

Test Case: "should pass actionsDenylist option to Redux DevTools"

Purpose: Verifies that the actionsDenylist option is correctly passed through to Redux DevTools Extension

What it tests:

  1. Option Pass-Through: Confirms the middleware properly forwards actionsDenylist to Redux DevTools
  2. Type Compatibility: Validates that array format (['secret.*']) is correctly handled
  3. Extension Integration: Ensures extensionConnector.connect() receives the option in its configuration object

Test Implementation Details:

  • Sets up a store with actionsDenylist: ['secret.*']
  • Creates a minimal store state to test the option without action execution complexity
  • Uses expect.objectContaining() to verify the option exists in the connection config
  • Validates the exact value passed matches the configured pattern

Why this test is important:

  • Prevents breaking changes to the option name or format
  • Ensures TypeScript types align with runtime behavior
  • Verifies compatibility with Redux DevTools Extension API
  • Guards against accidental removal or modification of the feature

Test Coverage Stats

  • ✅ All 58 tests passing (including the new actionsDenylist test)
  • ✅ No test failures or regressions introduced
  • ✅ Maintains 100% success rate of existing test suite

Integration with Existing Tests

The new test integrates seamlessly with the existing DevTools test infrastructure:

  • Uses the same createStore helper function
  • Leverages existing getNamedConnectionApis utility
  • Follows established testing patterns for DevTools options
  • Maintains consistency with other option tests (e.g., name, store, enabled)

Future-Proofing

This test ensures:

  • Any refactoring of the DevTools middleware will catch breaking changes
  • Documentation examples remain accurate and functional
  • The feature continues working as Redux DevTools Extension evolves
  • Developers can confidently rely on the actionsDenylist option

Test Implementation

describe('actionsDenylist', () => {
  it('should pass actionsDenylist option to Redux DevTools', async () => {
    const options = {
      name: 'test-filter',
      enabled: true,
      actionsDenylist: ['secret.*'],
    }
    const api = createStore(devtools(() => ({ count: 0 }), options))

    const extensionConnector = (window as any).__REDUX_DEVTOOLS_EXTENSION__
    expect(extensionConnector.connect).toHaveBeenCalledWith(
      expect.objectContaining({
        actionsDenylist: ['secret.*'],
      }),
    )
  })
})

Benefits

  • Complete Documentation: Users can easily understand and implement action filtering
  • Practical Examples: Real-world use cases help developers apply the feature correctly
  • Test Coverage: Ensures the option works as expected and prevents regressions
  • Developer Experience: Clear guidance on regex patterns and filtering behavior

Files Modified

  • docs/middlewares/devtools.md - Added comprehensive documentation section
  • tests/devtools.test.tsx - Added test coverage for the option

Testing

  • ✅ All tests passing (58/58)
  • ✅ No TypeScript errors
  • ✅ Documentation examples verified

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
zustand-demo Ready Ready Preview Comment Oct 31, 2025 4:17am

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Oct 7, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@totorototo totorototo changed the title Filter out specific actions from being sent to Redux DevTools feat: filter out specific actions from being sent to Redux DevTools Oct 7, 2025
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Oct 8, 2025

demostarter

npm i https://pkg.pr.new/zustand@3252

commit: ee13e7b

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 18, 2025

Thanks for the suggestion.

similar to the actionBlacklist feature in Redux DevTools.

Could you put the link to the feature in Redux DevTools?

Copy link
Copy Markdown
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks reasonable in general.

@totorototo
Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion.

similar to the actionBlacklist feature in Redux DevTools.

Could you put the link to the feature in Redux DevTools?

here it is:

https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md#actionsdenylist--actionsallowlist

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 24, 2025

Let's use the same terminology actionsDenylist and same signature string | string[] then.

Copy link
Copy Markdown
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, do we just need to passthrough it? That's sweet.

Remaining:

  • fix CI error (format?)
  • update README

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 27, 2025

Thanks. Please run prettier, which should be easier.

update README

Oops, I meant the PR description. But, fixing the docs is great!

@dai-shi dai-shi changed the title feat: filter out specific actions from being sent to Redux DevTools docs and tests: filter out specific actions from being sent to Redux DevTools Oct 29, 2025
@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 29, 2025

Hm, merging main causes the CI failure? Could you check it? Let me know if you need any help.
Also, please update PR description to focus on docs and tests.

@totorototo
Copy link
Copy Markdown
Contributor Author

Hm, merging main causes the CI failure? Could you check it? Let me know if you need any help. Also, please update PR description to focus on docs and tests.

Sure, I will!

@totorototo
Copy link
Copy Markdown
Contributor Author

tests passed locally. linter / formatter issue from time to time.

Copy link
Copy Markdown
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for your contribution!

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 31, 2025

We need to figure out how CIs are failing.
It seems unrelated to this PR change, but it's related with devtools. Maybe you have some insight?

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 31, 2025

We need to figure out how CIs are failing. It seems unrelated to this PR change, but it's related with devtools. Maybe you have some insight?

#3246 (comment)

@dai-shi dai-shi merged commit d25a4d2 into pmndrs:main Oct 31, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants