Skip to content

Conversation

@wolfmanfx
Copy link
Collaborator

Closes #213

Summary

  • Prevents runtime errors and blank DevTools by making rename operations stable, idempotent, and safe during component unmount.
  • Corrects state cleanup to avoid corrupting DevTools state when a store is removed.

Changes

  • Rename stability

    • Added renameStoreById(id, newName) and switched withDevtools() to call it.
    • Centralized shared logic in private #applyRename(id, oldName, newName).
    • Made rename idempotent (no-op if name unchanged).
    • Duplicate-name checks ignore the current store.
  • State cleanup fix

    • In removeStore, preserve entries using the iterator key (storeName) instead of the removed store’s name.
  • Demo consistency

    • TodoStore.remove now also removes the id from selectedIds to keep selection and entities in sync. This leaded also to errors.

Why

  • Unchecking/destroying a detail component could trigger a rename after its store was removed; name-based lookup returned null/undefined and threw.
  • Rebuilding #currentState using the removed store’s name re-keyed all survivors incorrectly, corrupting the DevTools view.

How to verify

  1. Start the demo and open Redux DevTools.
  2. Select multiple todos to render details; toggle selection (check/uncheck).
  3. Delete a selected todo.
  4. Expected:
    • No runtime errors.
    • DevTools shows stable, correctly renamed store entries.
    • No state corruption when removing/renaming stores.

Affected files

  • libs/ngrx-toolkit/src/lib/devtools/internal/devtools-syncer.service.ts
  • libs/ngrx-toolkit/src/lib/devtools/with-devtools.ts
  • apps/demo/src/app/devtools/todo-store.ts

Notes

  • No breaking changes expected.
  • Builds and demo run pass locally.

Commands

pnpm build:all
pnpm start
pnpm test:e2e

@jdegand
Copy link

jdegand commented Sep 6, 2025

In with-devtools, on line 26, you can remove EXISTING_NAMES, the import of InjectionToken and you can safely remove const id = String(store[uniqueDevtoolsId]()); inside onInit.

Copy link
Collaborator

@rainerhahnekamp rainerhahnekamp left a comment

Choose a reason for hiding this comment

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

Good work, there is actually just one thing I've found.

Copy link
Collaborator

@rainerhahnekamp rainerhahnekamp left a comment

Choose a reason for hiding this comment

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

Wonderful

@rainerhahnekamp rainerhahnekamp merged commit 8a9d13a into angular-architects:main Sep 8, 2025
1 check 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.

withDevTools() not working in demo app?

4 participants