+
Skip to content

refactor(store): make execution stategies tree-shakable #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

arturovt
Copy link
Member

@arturovt arturovt commented Mar 29, 2025

NGXS has moved towards reducing bundle size by removing unnecessary code in production.

Currently, execution strategies are not tree-shakable because they are explicitly
referenced in the code. We should invert control and require developers to explicitly
provide an execution strategy.

When zoneless change detection is enabled and NoopNgxsExecutionStrategy is used,
DispatchOutsideZoneNgxsExecutionStrategy remains in the initial bundle, increasing
the final size even though it is never used — and vice versa.

With this commit, we make options a required parameter and options.executionStrategy a
required property, ensuring that developers always specify an execution strategy.

BREAKING CHANGE: The options parameter is now required when calling forRoot() or
provideStore(), as developers must provide an execution strategy. This should be a
straightforward change, as developers only need to specify
{ executionStrategy: DispatchOutsideZoneNgxsExecutionStrategy }.

Copy link

nx-cloud bot commented Mar 29, 2025

View your CI Pipeline Execution ↗ for commit 22814a9.

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

☁️ Nx Cloud last updated this comment at 2025-03-29 15:41:30 UTC

Copy link

nx-cloud bot commented Mar 29, 2025

View your CI Pipeline Execution ↗ for commit 7036d7f.

Command Status Duration Result
nx run-many --target=build --all ✅ Succeeded 1m 18s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-29 13:34:42 UTC

Copy link

pkg-pr-new bot commented Mar 29, 2025

Open in Stackblitz

@ngxs/devtools-plugin

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

@ngxs/form-plugin

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

@ngxs/hmr-plugin

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

@ngxs/router-plugin

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

@ngxs/storage-plugin

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

@ngxs/store

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

@ngxs/websocket-plugin

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

commit: 22814a9

@arturovt arturovt force-pushed the refactor/tree-shake-strategies branch from 7036d7f to f9c4d73 Compare March 29, 2025 13:50
Copy link

codeclimate bot commented Mar 29, 2025

Code Climate has analyzed commit f9c4d73 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 95.3% (0.0% change).

View more on Code Climate.

NGXS has moved towards reducing bundle size by removing unnecessary code in production.

Currently, execution strategies are not tree-shakable because they are explicitly
referenced in the code. We should invert control and require developers to explicitly
provide an execution strategy.

When zoneless change detection is enabled and `NoopNgxsExecutionStrategy` is used,
`DispatchOutsideZoneNgxsExecutionStrategy` remains in the initial bundle, increasing
the final size even though it is never used — and vice versa.

With this commit, we make `options` a required parameter and `options.executionStrategy` a
required property, ensuring that developers always specify an execution strategy.

**BREAKING CHANGE**: The `options` parameter is now required when calling `forRoot()` or
`provideStore()`, as developers must provide an execution strategy. This should be a
straightforward change, as developers only need to specify
`{ executionStrategy: DispatchOutsideZoneNgxsExecutionStrategy }`.
@arturovt arturovt force-pushed the refactor/tree-shake-strategies branch from f9c4d73 to 22814a9 Compare March 29, 2025 15:37
@arturovt arturovt marked this pull request as ready for review March 29, 2025 15:37
@arturovt arturovt merged commit 81c7a7c into master Mar 29, 2025
3 checks passed
@arturovt arturovt deleted the refactor/tree-shake-strategies branch March 29, 2025 15:37
arturovt added a commit that referenced this pull request May 9, 2025
arturovt added a commit that referenced this pull request May 9, 2025
* Revert "chore: migrate executionStrategy (#2317)"

This reverts commit 2b2355c.

* Revert "refactor(store): inline `NGXS_EXECUTION_STRATEGY` factory"

This reverts commit 5bb8fb6.

* Revert "refactor(store): make execution stategies tree-shakable (#2316)"

This reverts commit 81c7a7c.
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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载