Skip to content

Cache unchanged dynamic middleware chains - #5415

Merged
markerikson merged 1 commit into
reduxjs:masterfrom
OskarEichler:codex/cache-dynamic-middleware-chain
Sep 19, 2026
Merged

markerikson merged 1 commit into
reduxjs:masterfrom
OskarEichler:codex/cache-dynamic-middleware-chain

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

Improvement

  • Compose and apply the dynamic middleware chain only when the registered middleware set changes.
  • Reuse the resulting dispatch function for ordinary actions.
  • Preserve immediate visibility of newly added middleware for nested dispatches.

Why

The current hot path rebuilds an array, calls compose, and reapplies every middleware to next for every dispatched action, even though middleware additions are comparatively rare. This moves that work to the first dispatch after an actual addition.

The focused regression counts middleware-chain application. Exact master applies the first middleware twice for two unchanged dispatches; this change applies it once, then exactly once more after a second middleware is added. A nested-dispatch regression verifies that additions made during middleware execution are visible immediately.

Verification

  • Focused dynamic middleware suite: 4 tests pass, zero type errors.
  • Full Toolkit suite: 88 files, 1,320 tests pass, two existing todos, zero type errors.
  • Package build passes.
  • Declaration/type tests pass.
  • Changed-file Prettier and whitespace checks pass.

No public API, type, dispatch result, middleware order, or addition semantics change.

@codesandbox

codesandbox Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor β€’ VS Code β€’ Insiders

Open Preview

@netlify

netlify Bot commented Aug 30, 2026

Copy link
Copy Markdown

βœ… Deploy Preview for redux-starter-kit-docs ready!

Name Link
πŸ”¨ Latest commit d391ada
πŸ” Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/6a938cbfa88ed80008459755
😎 Deploy Preview https://deploy-preview-5415--redux-starter-kit-docs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
πŸ€– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@reduxjs/rtk-codemods

npm i https://pkg.pr.new/@reduxjs/rtk-codemods@d391ada -D
yarn add https://pkg.pr.new/@reduxjs/rtk-codemods@d391ada.tgz -D
pnpm add https://pkg.pr.new/@reduxjs/rtk-codemods@d391ada.tgz -D
bun add https://pkg.pr.new/@reduxjs/rtk-codemods@d391ada.tgz -D

@rtk-query/codegen-openapi

npm i https://pkg.pr.new/@rtk-query/codegen-openapi@d391ada -D
yarn add https://pkg.pr.new/@rtk-query/codegen-openapi@d391ada.tgz -D
pnpm add https://pkg.pr.new/@rtk-query/codegen-openapi@d391ada.tgz -D
bun add https://pkg.pr.new/@rtk-query/codegen-openapi@d391ada.tgz -D

@rtk-query/graphql-request-base-query

npm i https://pkg.pr.new/@rtk-query/graphql-request-base-query@d391ada -D
yarn add https://pkg.pr.new/@rtk-query/graphql-request-base-query@d391ada.tgz -D
pnpm add https://pkg.pr.new/@rtk-query/graphql-request-base-query@d391ada.tgz -D
bun add https://pkg.pr.new/@rtk-query/graphql-request-base-query@d391ada.tgz -D

@reduxjs/toolkit

npm i https://pkg.pr.new/@reduxjs/toolkit@d391ada -D
yarn add https://pkg.pr.new/@reduxjs/toolkit@d391ada.tgz -D
pnpm add https://pkg.pr.new/@reduxjs/toolkit@d391ada.tgz -D
bun add https://pkg.pr.new/@reduxjs/toolkit@d391ada.tgz -D

commit: d391ada

@markerikson
markerikson merged commit 2590de2 into reduxjs:master Sep 19, 2026
45 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.

3 participants