Skip to content

fix(store): warn when state is mutated after injector destruction#2407

Merged
arturovt merged 1 commit into
masterfrom
fix/skip-mutation-warning
Mar 27, 2026
Merged

fix(store): warn when state is mutated after injector destruction#2407
arturovt merged 1 commit into
masterfrom
fix/skip-mutation-warning

Conversation

@arturovt
Copy link
Copy Markdown
Member

@arturovt arturovt commented Mar 27, 2026

patchState and setState previously silently no-oped when called after the
injector was destroyed. This made it hard to diagnose unexpected silent
failures, particularly in SSR scenarios where finalize() operators can
run after the app has been torn down.

Both methods now emit a console.warn that includes the attempted value,
the state path, and a note explaining common conditions under which this
can occur. The warning is gated on ngDevMode in browser builds to avoid
bundle bloat, but always fires when ngServerMode is active — bundle size
is not a concern on the server and silently dropped mutations are critical
enough to always surface in server logs.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 27, 2026

View your CI Pipeline Execution ↗ for commit aa9d366

Command Status Duration Result
nx run-many --target=test --all --configuration... ✅ Succeeded 2m 36s View ↗
nx run-many --target=lint --all --exclude=creat... ✅ Succeeded 5s View ↗
nx lint-types store ✅ Succeeded <1s View ↗
nx run-many --target=build --all ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-27 22:41:46 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 27, 2026

Open in StackBlitz

@ngxs/devtools-plugin

npm i https://pkg.pr.new/@ngxs/devtools-plugin@2407

@ngxs/form-plugin

npm i https://pkg.pr.new/@ngxs/form-plugin@2407

@ngxs/hmr-plugin

npm i https://pkg.pr.new/@ngxs/hmr-plugin@2407

@ngxs/router-plugin

npm i https://pkg.pr.new/@ngxs/router-plugin@2407

@ngxs/storage-plugin

npm i https://pkg.pr.new/@ngxs/storage-plugin@2407

@ngxs/store

npm i https://pkg.pr.new/@ngxs/store@2407

@ngxs/websocket-plugin

npm i https://pkg.pr.new/@ngxs/websocket-plugin@2407

commit: aa9d366

@arturovt arturovt force-pushed the fix/skip-mutation-warning branch from 9ee48a6 to 87617a2 Compare March 27, 2026 22:33
@arturovt arturovt changed the title fix(store): add dev-mode warnings when state is mutated after injector destruction fix(store): warn when state is mutated after injector destruction Mar 27, 2026
patchState and setState previously silently no-oped when called after the
injector was destroyed. This made it hard to diagnose unexpected silent
failures, particularly in SSR scenarios where finalize() operators can
run after the app has been torn down.

Both methods now emit a console.warn that includes the attempted value,
the state path, and a note explaining common conditions under which this
can occur. The warning is gated on ngDevMode in browser builds to avoid
bundle bloat, but always fires when ngServerMode is active — bundle size
is not a concern on the server and silently dropped mutations are critical
enough to always surface in server logs.
@arturovt arturovt force-pushed the fix/skip-mutation-warning branch from 87617a2 to aa9d366 Compare March 27, 2026 22:34
@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Mar 27, 2026

BundleMon

Files updated (1)
Status Path Size Limits
fesm2022/ngxs-store.mjs
111.6KB (+1.67KB +1.52%) 110KB / +0.5%
Unchanged files (5)
Status Path Size Limits
fesm2022/ngxs-store-internals.mjs
13.74KB 15KB / +0.5%
fesm2022/ngxs-store-internals-testing.mjs
10.32KB 13KB / +0.5%
fesm2022/ngxs-store-operators.mjs
6.05KB 7KB / +0.5%
fesm2022/ngxs-store-plugins.mjs
2.37KB 3KB / +0.5%
fesm2022/ngxs-store-experimental.mjs
574B 2KB / +0.5%

Total files change +1.67KB +1.17%

Groups updated (1)
Status Path Size Limits
@ngxs/store(fesm2022)[gzip]
./fesm2022/*.mjs
35.54KB (+308B +0.85%) +1%

Final result: ❌

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Mar 27, 2026

BundleMon (NGXS Plugins)

Unchanged files (9)
Status Path Size Limits
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin.m
js
4.1KB +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin.mjs
3.4KB +0.5%
Plugins(fesm2022)[gzip]
hmr-plugin/fesm2022/ngxs-hmr-plugin.mjs
2.72KB +0.5%
Plugins(fesm2022)[gzip]
websocket-plugin/fesm2022/ngxs-websocket-plug
in.mjs
2.58KB +0.5%
Plugins(fesm2022)[gzip]
form-plugin/fesm2022/ngxs-form-plugin.mjs
2.47KB +0.5%
Plugins(fesm2022)[gzip]
devtools-plugin/fesm2022/ngxs-devtools-plugin
.mjs
2.23KB +0.5%
Plugins(fesm2022)[gzip]
logger-plugin/fesm2022/ngxs-logger-plugin.mjs
2.03KB +0.5%
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin-i
nternals.mjs
947B +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin-int
ernals.mjs
453B +0.5%

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
All Plugins(fesm2022)[gzip]
./-plugin/fesm2022/.mjs
20.89KB +0.5%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Mar 27, 2026

BundleMon (Integration Projects)

Unchanged files (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng21/dist-integration/browser/mai
n-(hash).js
67.23KB +1%

No change in files bundle size

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@arturovt arturovt merged commit 19fbcb2 into master Mar 27, 2026
15 of 16 checks passed
@arturovt arturovt deleted the fix/skip-mutation-warning branch March 27, 2026 22:41
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.

1 participant