Releases: reduxjs/redux-thunk
v3.1.0
This major release:
- Updates the packaging for better ESM/CJS compatibility
- Changes the package to use named exports instead of a default export
This release has breaking changes. (Note: this actually points to v3.1.0, which includes a hotfix that was meant for 3.0.0.)
This release is part of a wave of major versions of all the Redux packages: Redux Toolkit 2.0, Redux core 5.0, React-Redux 9.0, Reselect 5.0, and Redux Thunk 3.0.
For full details on all of the breaking changes and other significant changes to all of those packages, see the "Migrating to RTK 2.0 and Redux 5.0" migration guide in the Redux docs.
Note
The Redux core, Reselect, and Redux Thunk packages are included as part of Redux Toolkit, and RTK users do not need to manually upgrade them - you'll get them as part of the upgrade to RTK 2.0. (If you're not using Redux Toolkit yet, please start migrating your existing legacy Redux code to use Redux Toolkit today!)
# RTK
npm install @reduxjs/toolkit
yarn add @reduxjs/toolkit
# Standalone
npm install redux-thunk
yarn add redux-thunk
Changelog
Named Exports Instead of Default Exports
The redux-thunk
package previously used a single default export that was the thunk middleware, with an attached field named withExtraArgument
that allowed customization.
The default export has been removed. There are now two named exports: thunk
(the basic middleware) and withExtraArgument
.
If you are using Redux Toolkit, this should have no effect, as RTK already handles this inside of configureStore
.
ESM/CJS Package Compatibility
The biggest theme of the Redux v5 and RTK 2.0 releases is trying to get "true" ESM package publishing compatibility in place, while still supporting CJS in the published package.
The primary build artifact is now an ESM file, dist/redux-thunk.mjs
. Most build tools should pick this up. There's also a CJS artifact, and a second copy of the ESM file named redux-thunk.legacy-esm.js
to support Webpack 4 (which does not recognize the exports
field in package.json
).
Build Tooling
We're now building the package using https://github.com/egoist/tsup. We also now include sourcemaps for the ESM and CJS artifacts.
The repo has been updated to use Yarn 3 for dependencies and Vitest for running tests.
Dropping UMD Builds
Redux has always shipped with UMD build artifacts. These are primarily meant for direct import as script tags, such as in a CodePen or a no-bundler build environment.
For now, we're dropping those build artifacts from the published package, on the grounds that the use cases seem pretty rare today.
Since the code is so simple, the ESM artifact can be used directly in the browser via Unpkg.
If you have strong use cases for us continuing to include UMD build artifacts, please let us know!
extend-redux
Typedefs Removed
Redux Thunk 2.x included a redux-thunk/extend-redux
TS-only entry point, which extended the types of dispatch
and bindActionCreators
to globally give them knowledge of the thunk types. We feel that global overrides from a library are an anti-pattern, and we've removed this entry point. (Note: this ended up being released in 3.1.0, as it was missed in the original 3.0.0 release.)
Please follow our TS setup guidelines to infer the correct type of dispatch
for your store.
What's Changed
- Migrate thunk package to ESM by @markerikson in #340
- Switch package manager to Yarn 3 and update CI jobs by @markerikson in #341
- Run RTK publish CI examples on built artifact by @markerikson in #342
- Rewrite build/test setup and hopefully fix ESM compat by @markerikson in #344
- Change artifact names to be
redux-thunk
by @markerikson in #345 - Support Webpack 4 with a "legacy ESM" artifact by @markerikson in #346
- update README and types to match named export by @EskiMojo14 in #347
- Bump Redux peer dep for RC and update build tooling by @markerikson in #356
- Drop the extend-redux addition by @markerikson in #357
Full Changelog: v2.4.2...v3.1.0
v3.0.0-rc.0
This release candidate has no actual source code changes since the previous v3.0.0-beta.0
release.
Note that we hope to release Redux Toolkit 2.0, Redux core 5.0, and React-Redux 9.0 by the start of December! (If we don't hit that, we'll aim for January, after the holidays.)
See the preview Redux Toolkit 2.0 + Redux core 5.0 Migration Guide for an overview of breaking changes in RTK 2.0 and Redux core.
npm install redux-thunk@next
yarn add redux-thunk@next
What's Changed
- Bump Redux peer dep for RC and update build tooling by @markerikson in #356
Full Changelog: v3.0.0-beta.0...v3.0.0-rc.0
v3.0.0-beta.0
This beta release updates the TS types and tests to match the exports, and adds Redux 5.0.0-beta.0 as a valid peer dep.
What's Changed
- update README and types to match named export by @EskiMojo14 in #347
- [package.json] add ^5.0.0-beta.0" to peerDependencies by @ryota-murakami in #349
Full Changelog: v3.0.0-alpha.3...v3.0.0-beta.0
v3.0.0-alpha.3
This is an alpha release for Redux-Thunk 3.0. This release has many changes to our build setup and published package contents.
Also see the release notes for redux@5.0.0-alpha.4
.
Changelog
ESM/CJS Package Compatibility
The biggest theme of the Redux v5 and RTK 2.0 releases is trying to get "true" ESM package publishing compatibility in place, while still supporting CJS in the published package.
Earlier alphas made changes to the package.json
contents and published build artifacts in an attempt to get ESM+CJS compat working correctly, but those alphas had several varying compat issues.
We've set up a battery of example applications in the RTK repo that use a variety of build tools (currently CRA4, CRA5, Next 13, and Vite, Node CJS mode, and Node ESM mode), to verify that Redux and Redux Toolkit compile, import, and run correctly with both TS and various bundlers. We've also set up a check using a custom CLI wrapper around https://arethetypeswrong.github.io to check for potential packaging incompatibilities.
This release changes the names and contents of the published build artifacts, and the various exports/module/main
fields in package.json
to point to those.
The primary build artifact is now an ESM file, dist/redux-thunk.mjs
. Most build tools should pick this up. There's also a CJS artifact, and a second copy of the ESM file named redux-thunk.legacy-esm.js
to support Webpack 4 (which does not recognize the exports
field in package.json
).
As of this release, we think we have ESM+CJS compat working correctly, but we ask that the community try out the alphas in your apps and let us know of any compat problems!
Note: The one known potential issue is that TypeScript's new
moduleResolution: "node16"
mode may see a mismatch between the ESM artifacts and the TS typedefs when imported in a Node CJS environment, and [that may allow hypothetically-incorrect import usage. (See ongoing discussion in https://github.com/arethetypeswrong/arethetypeswrong.github.io/issues/21 .) In practice, we think that probably won't be a concern, and we'll do further investigation before a final release.
Build Tooling
We're now building the package using https://github.com/egoist/tsup . It looks like the output is effectively equivalent, but please let us know if there's any issues.
We also now include sourcemaps for the ESM and CJS artifacts.
The repo has been updated to use Yarn 3 for dependencies and Vitest for running tests.
Dropping UMD Builds
Redux has always shipped with UMD build artifacts. These are primarily meant for direct import as script tags, such as in a CodePen or a no-bundler build environment.
For now, we're dropping those build artifacts from the published package, on the grounds that the use cases seem pretty rare today.
Since the code is so simple, the ESM artifact can be used directly in the browser via Unpkg.
If you have strong use cases for us continuing to include UMD build artifacts, please let us know!
What's Changed
- Migrate thunk package to ESM by @markerikson in #340
- Switch package manager to Yarn 3 and update CI jobs by @markerikson in #341
- Run RTK publish CI examples on built artifact by @markerikson in #342
- Rewrite build/test setup and hopefully fix ESM compat by @markerikson in #344
- Change artifact names to be
redux-thunk
by @markerikson in #345 - Support Webpack 4 with a "legacy ESM" artifact by @markerikson in #346
Full Changelog: v3.0.0-alpha.1...v3.0.0-alpha.3
v3.0.0-alpha.1
This is the initial alpha release for Redux Thunk 3.0. This release has breaking changes.
Changelog
ESM Migration
In conjunction with the Redux Toolkit 2.0 alpha development work, we've migrated the package definition to be a full {type: "module"}
ESM package (with CJS still included for compatibility purposes).
Default Export Converted to Named Exports
As part of that ESM migration, we've dropped the existing default export in favor of named exports. Migration of user code should be straightforward:
// Previously: a default export that has `withExtraArgument` attached
- import thunk from 'redux-thunk'
// Now: separate named exports, no default export
+ import { thunk, withExtraArgument } from 'redux-thunk'
That said, users really should be using configureStore
from Redux Toolkit instead, which already automatically adds the thunk middleware to the Redux store.
v2.4.2
This release removes an unused TS type that caused errors when users were type-checking libraries in node_modules
.
What's Changed
- Remove unused type by @antoniopresto in #328
Full Changelog: v2.4.1...v2.4.2
v2.4.1
This release adds an explicit plain action
overload to the ThunkDispatch
TS type to better handle inference of the return value in some cases.
What's Changed
- Improve action return value resolution by @markerikson in #327
Full Changelog: v2.4.0...v2.4.1
v2.4.0
This very overdue release makes several major improvements to the TypeScript types, and converts the actual source to TypeScript. Sorry for the delay!
Changelog
TypeScript Improvements
This release fixes several outstanding issues that had been reported with the types. An extra overload has been added to let TS correctly understand some generically-typed values being passed to dispatch
, and the overloads have been reworked for additional compatibility.
There's also a new ThunkActionDispatch
type that can be used to represent how bindActionCreators
turns bound thunks into (arg) => thunkReturnValue
.
Additionally, all of the generic args have been giving meaningful names instead of one-letter abbreviations (S
-> State
, E
-> ExtraArgument
, etc), and we've added descriptive comments in the type definitions for clarity.
Optional Global Dispatch
Type Extension
Most Redux apps have the thunk middleware enabled, but the default Dispatch
and bindActionCreator
types only know about the standard behavior of a basic Redux store without any middleware. The thunk middleware types add to that type behavior, so that Dispatch
knows dispatching a thunk can actually return a value such as a Promise.
We generally recommend inferring the type of dispatch
and using that to create reusable types, including creating pre-typed hooks. However, some users may prefer to globally augment the Dispatch
type to always use the additional thunk behavior.
You can now import 'redux-thunk/extend-redux'
to globally augment the Dispatch
type as an opt-in change in behavior.
Codebase Converted to TypeScript
We've gone ahead and converted the actual source to TS. Since the source was only 15-ish lines to begin with, most of the "conversion" time was just trying to convince TS that assigning thunk.extraArgument = createThunkMiddleware
was a legal operation :)
We also updated the build tooling:
- Babel updates
- Rollup for the UMDs instead of Webpack
- Github Actions for CI instead of Travis
Finally, the README has been updated with newer instructions and usage information.
What's Changed
- Change misleading parameter name for overload of ThunkDispatch by @jmrog in #216
- --save no longer needed by @JoeCortopassi in #217
- Allow action to be typed with any by @laat in #219
- Add overload for bindActionCreators by @RMHonor in #224
- promote gender neutral docs by @beatfactor in #234
- Clarify terminology by @jmm in #237
- Provide more informative names for TypeScript type params by @agwells in #243
- Add peer dependency on redux 4.0 by @hedgepigdaniel in #251
- chore: remove 2015 preset and add env by @hozefaj in #236
- #248 Add union overload to ThunkDispatch by @Philipp91 in #255
- fix: extraThunkArgument types by @jedmao in #260
- Upgrade dependencies by @jedmao in #261
- Add Prettier by @jedmao in #262
- fix: typo TExtraThunkARg -> TExtraThunkArg by @jedmao in #263
- declare this package as having no side effects by @VincentBailly in #267
- Reflect rename of Redux Starter Kit by @travigd in #270
- Correct destructuring example by @telegraham in #272
- Fix link by @mhienle in #276
- feat(ts): add Dispatch overload to redux module by @iamandrewluca in #278
- docs: fix link for
applyMiddleware
by @iamandrewluca in #279 - Improved wording in README.md by @haricharanbole in #293
- chore: add yarn add line by @RichardBray in #305
- Use "sh" instead of "js" in install instructions by @EvanHahn in #312
- Remove redundant
|
by @Philipp91 in #317 - Use GitHub Actions by @nickmccurdy in #318
- Update TS dev tooling and GH Actions workflow by @markerikson in #320
- Move Redux module type extension into a separate imported file by @markerikson in #321
- Add CodeSandbox CI by @markerikson in #323
- Convert codebase to TS and update build tooling by @markerikson in #322
- Remove Webpack config and try test build by @markerikson in #324
New Contributors
- @jmrog made their first contribution in #216
- @JoeCortopassi made their first contribution in #217
- @laat made their first contribution in #219
- @RMHonor made their first contribution in #224
- @beatfactor made their first contribution in #234
- @jmm made their first contribution in #237
- @agwells made their first contribution in #243
- @hedgepigdaniel made their first contribution in #251
- @hozefaj made their first contribution in #236
- @Philipp91 made their first contribution in #255
- @jedmao made their first contribution in #260
- @VincentBailly made their first contribution in #267
- @travigd made their first contribution in #270
- @telegraham made their first contribution in #272
- @mhienle made their first contribution in #276
- @iamandrewluca made their first contribution in #278
- @haricharanbole made their first contribution in #293
- @RichardBray made their first contribution in #305
- @EvanHahn made their first contribution in #312
- @nickmccurdy made their first contribution in #318
- @markerikson made their first contribution in #320
Full Changelog: v2.3.0...v2.4.0
v2.3.0
Hello! There's a new sheriff in town...
This is only an update to the TypeScript typings for Redux 4.0 compatibility. After some discussion on the issues/PRs, we're going to be removing the typings completely in a 3.0 release soon. They will instead live in DefinitelyTyped, where they can be updated to match newer version of TypeScript and Redux at whatever pace they want to take. Farewell, typings! 🖖
- Updated TypeScript typings for Redux 4.0 (#180 by @Cryrivers)