Skip to content

Commit 1c12ef2

Browse files
committed
Merge branch 'master' into combineslices-example
2 parents e97fed0 + d7119ba commit 1c12ef2

File tree

13 files changed

+528
-1606
lines changed

13 files changed

+528
-1606
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
name: size
2-
on: [pull_request]
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
permissions:
7+
pull-requests: write
38
jobs:
49
size:
510
runs-on: ubuntu-latest
611
env:
712
CI_JOB_NUMBER: 1
813
steps:
914
- uses: actions/checkout@v2
10-
- uses: andresz1/size-limit-action@v1
15+
- uses: EskiMojo14/size-limit-action@v1
1116
with:
1217
directory: packages/toolkit
1318
github_token: ${{ secrets.GITHUB_TOKEN }}
1419
build_script: build-only
20+
package_manager: yarn
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/get-config.js b/get-config.js
2+
index 76ebaee5455b2a4bacb986784bd1b53ad89adeb7..1b092e645b258f4a6533ca88b7d36dbcde4eb6de 100644
3+
--- a/get-config.js
4+
+++ b/get-config.js
5+
@@ -132,7 +132,7 @@ export default async function getConfig(plugins, process, args, pkg) {
6+
} else if (!check.entry) {
7+
if (pkg.packageJson.main) {
8+
processed.files = [
9+
- require.resolve(join(dirname(pkg.path), pkg.packageJson.main))
10+
+ import.meta.resolve(join(dirname(pkg.path), pkg.packageJson.main))
11+
]
12+
} else {
13+
processed.files = [join(dirname(pkg.path), 'index.js')]
14+
@@ -177,7 +177,7 @@ export default async function getConfig(plugins, process, args, pkg) {
15+
for (let i in check.import) {
16+
if (peer.includes(i)) {
17+
check.ignore = check.ignore.filter(j => j !== i)
18+
- imports[require.resolve(i, config.cwd)] = check.import[i]
19+
+ imports[import.meta.resolve(i, config.cwd)] = check.import[i]
20+
} else {
21+
imports[toAbsolute(i, config.cwd)] = check.import[i]
22+
}

CONTRIBUTING.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,59 @@ Before opening an issue, please search the [issue tracker](https://github.com/re
88

99
Please ask any general and implementation specific questions on [Stack Overflow with a Redux Toolkit tag](http://stackoverflow.com/questions/tagged/redux-toolkit?sort=votes&pageSize=50) for support.
1010

11-
## New Features
11+
We ask you to do this because StackOverflow has a much better job at keeping popular questions visible. Unfortunately good answers get lost and outdated on GitHub.
1212

13-
Please open an issue with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept.
13+
If your question gets closed or you don't get a reply after a few days, consider opening a [discussion](https://github.com/reduxjs/redux-toolkit/discussions) or joining the [Reactiflux](https://discord.gg/reactiflux) discord server and asking in the #redux channel.
14+
15+
### Help Us Help You
16+
17+
On both websites, it is a good idea to structure your code and question in a way that is easy to read to help people to answer it. For example, we encourage you to use syntax highlighting, indentation, and split text in paragraphs.
18+
19+
Please keep in mind that people spend their free time trying to help you. You can make it easier for them if you provide versions of the relevant libraries and a runnable small project reproducing your issue. You can put your code on [JSBin](https://jsbin.com) or, for bigger projects, on GitHub. Make sure all the necessary dependencies are declared in `package.json` so anyone can run `npm install && npm start` and reproduce your issue.
20+
21+
## Ways You Can Contribute
22+
23+
There are several ways you can contribute to the repository. Instead of developing a feature or fixing a bug, you can also contribute by updating or writing [documentation](https://github.com/reduxjs/redux-toolkit/tree/master/docs) for a specific feature or implementation if you know you are good with documentation. Alternatively, you can add [examples](https://github.com/reduxjs/redux-toolkit/tree/master/examples) of any 3rd party implementation like GraphQL or React (just an example) that would help users to understand and easily integrate Redux Toolkit with that specific framework and library.
1424

1525
## Getting started
1626

1727
Visit the [Issue tracker](https://github.com/reduxjs/redux-toolkit/issues) to find a list of open issues that need attention.
1828

29+
### Bugs and Improvements
30+
31+
We use the [Issue tracker](https://github.com/reduxjs/redux-toolkit/issues) to keep track of bugs and improvements to Redux Toolkit itself, its examples, and the documentation. We encourage you to open issues to discuss improvements, architecture, theory, internal implementation, etc. If a topic has been discussed before, we will ask you to join the previous discussion.
32+
33+
### New Features
34+
35+
Please open an [issue](https://github.com/reduxjs/redux-toolkit/issues) with a proposal for a new feature or refactoring before starting on the work. We don't want you to waste your efforts on a pull request that we won't want to accept.
36+
1937
### Fork the repository
2038

2139
Please use the GitHub UI to [fork this repository](https://github.com/reduxjs/redux-toolkit) (_read more about [Forking a repository](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo)_). Redux Toolkit has forked builds enabled in the CI, so you will see the build status of your fork's branch.
2240

41+
![Fork Button](https://docs.github.com/assets/cb-40742/mw-1440/images/help/repository/fork-button.webp)
42+
43+
Fork, then clone the repo:
44+
45+
```sh
46+
git clone https://github.com/your-username/redux-toolkit.git
47+
```
48+
2349
### Install
2450

2551
```bash
2652
$ cd redux-toolkit
2753
$ yarn
2854
```
2955

56+
### Build
57+
58+
You can build the packages with the following command:
59+
60+
```
61+
yarn build
62+
```
63+
3064
### Tests
3165

3266
You can run tests for all packages with:
@@ -41,14 +75,6 @@ To continuously watch and run tests, run the following:
4175
yarn test --watch
4276
```
4377

44-
### Build
45-
46-
You can build the packages with the following command:
47-
48-
```
49-
yarn build
50-
```
51-
5278
## Git workflow / Submitting Changes
5379

5480
- Open a new issue in the [Issue tracker](https://github.com/reduxjs/redux-toolkit/issues).

docs/api/createSlice.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ create.preparedReducer(
240240

241241
Creates an async thunk instead of an action creator.
242242

243-
:::warning Setup
243+
:::caution Setup
244244

245245
To avoid pulling `createAsyncThunk` into the bundle size of `createSlice` by default, some extra setup is required to use `create.asyncThunk`.
246246

docs/rtk-query/api/created-api/hooks.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ type UseQuery = (
251251

252252
type UseQueryOptions = {
253253
pollingInterval?: number
254+
skipPollingIfUnfocused?: boolean
254255
refetchOnReconnect?: boolean
255256
refetchOnFocus?: boolean
256257
skip?: boolean
@@ -445,6 +446,7 @@ type UseQuerySubscriptionOptions = {
445446
skip?: boolean
446447
refetchOnMountOrArgChange?: boolean | number
447448
pollingInterval?: number
449+
skipPollingIfUnfocused?: boolean
448450
refetchOnReconnect?: boolean
449451
refetchOnFocus?: boolean
450452
}
@@ -485,6 +487,7 @@ type UseLazyQuery = (
485487

486488
type UseLazyQueryOptions = {
487489
pollingInterval?: number
490+
skipPollingIfUnfocused?: boolean
488491
refetchOnReconnect?: boolean
489492
refetchOnFocus?: boolean
490493
selectFromResult?: (result: UseQueryStateDefaultResult) => any
@@ -555,6 +558,7 @@ type UseLazyQuerySubscription = (
555558

556559
type UseLazyQuerySubscriptionOptions = {
557560
pollingInterval?: number
561+
skipPollingIfUnfocused?: boolean
558562
refetchOnReconnect?: boolean
559563
refetchOnFocus?: boolean
560564
}

docs/rtk-query/usage/polling.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ description: 'RTK Query > Usage > Polling: re-fetching data on a timer'
1414

1515
Polling gives you the ability to have a 'real-time' effect by causing a query to run at a specified interval. To enable polling for a query, pass a `pollingInterval` to the `useQuery` hook or action creator with an interval in milliseconds:
1616

17+
:::tip
18+
Polling additionally has the ability to skip sending requests while the window is out of focus. To enable this behavior, pass `skipPollingIfUnfocused: true` to the `useQuery` hook or action creator.
19+
20+
_Note: `skipPollingIfUnfocused` requires [`setupListeners`](../api/setupListeners.mdx) to have been called._
21+
:::
22+
1723
```tsx no-transpile title="src/Pokemon.tsx" no-transpile
1824
import * as React from 'react'
1925
import { useGetPokemonByNameQuery } from './services/pokemon'
2026

2127
export const Pokemon = ({ name }: { name: string }) => {
22-
// Automatically refetch every 3s
28+
// Automatically refetch every 3s unless the window is out of focus
2329
const { data, status, error, refetch } = useGetPokemonByNameQuery(name, {
2430
pollingInterval: 3000,
31+
skipPollingIfUnfocused: true,
2532
})
2633

2734
return <div>{data}</div>

packages/rtk-query-codegen-openapi/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/jest": "^27",
4040
"@types/lodash": "^4.14.165",
4141
"@types/node": "^14.14.12",
42+
"@types/node-fetch": "^2.6.11",
4243
"@types/prettier": "^2.1.6",
4344
"@types/semver": "^7.3.9",
4445
"babel-jest": "^26.6.3",
@@ -49,6 +50,7 @@
4950
"husky": "^4.3.6",
5051
"jest": "^29",
5152
"msw": "^0.40.2",
53+
"node-fetch": "^2.7.0",
5254
"openapi-types": "^9.1.0",
5355
"pretty-quick": "^3.1.0",
5456
"ts-jest": "^29",
Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,84 @@
11
const webpack = require('webpack')
22
let { join } = require('path')
33

4-
const suffixes = ['cjs.production.min.js', 'esm.js']
4+
const esmSuffixes = ['modern.mjs', 'browser.mjs', 'legacy-esm.js']
5+
const cjsSuffixes = ['development.cjs', 'production.min.cjs']
56

6-
function withRtkPath(suffix) {
7+
function withRtkPath(suffix, cjs = false) {
8+
/**
9+
* @param {string} name
10+
*/
11+
function alias(name) {
12+
return `${cjs ? 'cjs/' : ''}${name}.${suffix}`
13+
}
14+
/**
15+
* @param {webpack.Configuration} config
16+
*/
717
return (config) => {
818
config.plugins.push(
919
new webpack.NormalModuleReplacementPlugin(
1020
/@reduxjs\/toolkit\/query\/react/,
11-
join(__dirname, `query/react`),
21+
join(__dirname, 'dist/query/react/rtk-query-react.modern.mjs'),
1222
),
1323
new webpack.NormalModuleReplacementPlugin(
1424
/@reduxjs\/toolkit\/query/,
15-
join(__dirname, `query`),
25+
join(__dirname, 'dist/query/rtk-query.modern.mjs'),
26+
),
27+
new webpack.NormalModuleReplacementPlugin(
28+
/@reduxjs\/toolkit\/react/,
29+
join(__dirname, 'dist/react/redux-toolkit-react.modern.mjs'),
1630
),
1731
new webpack.NormalModuleReplacementPlugin(
1832
/@reduxjs\/toolkit/,
19-
join(__dirname),
33+
join(__dirname, 'dist/redux-toolkit.modern.mjs'),
2034
),
2135
new webpack.NormalModuleReplacementPlugin(
22-
/rtk-query-react.modern.js/,
36+
/rtk-query-react.modern.mjs/,
2337
(r) => {
2438
const old = r.request
2539
r.request = r.request.replace(
26-
/rtk-query-react.modern.js$/,
27-
`rtk-query-react.${suffix}`,
40+
/rtk-query-react.modern.mjs$/,
41+
alias('rtk-query-react'),
2842
)
29-
// console.log(old, '=>', r.request)
43+
//console.log(old, '=>', r.request)
3044
},
3145
),
32-
new webpack.NormalModuleReplacementPlugin(/rtk-query.modern.js/, (r) => {
46+
new webpack.NormalModuleReplacementPlugin(/rtk-query.modern.mjs/, (r) => {
3347
const old = r.request
3448
r.request = r.request.replace(
35-
/rtk-query.modern.js$/,
36-
`rtk-query.${suffix}`,
49+
/rtk-query.modern.mjs$/,
50+
alias('rtk-query'),
3751
)
38-
// console.log(old, '=>', r.request)
52+
//console.log(old, '=>', r.request)
3953
}),
4054
new webpack.NormalModuleReplacementPlugin(
41-
/redux-toolkit.modern.js$/,
55+
/redux-toolkit-react.modern.mjs$/,
56+
(r) => {
57+
const old = r.request
58+
r.request = r.request.replace(
59+
/redux-toolkit-react.modern.mjs$/,
60+
alias('redux-toolkit-react'),
61+
)
62+
//console.log(old, '=>', r.request)
63+
},
64+
),
65+
new webpack.NormalModuleReplacementPlugin(
66+
/redux-toolkit.modern.mjs$/,
4267
(r) => {
4368
const old = r.request
4469
r.request = r.request.replace(
45-
/redux-toolkit.modern.js$/,
46-
`redux-toolkit.${suffix}`,
70+
/redux-toolkit.modern.mjs$/,
71+
alias('redux-toolkit'),
4772
)
48-
// console.log(old, '=>', r.request)
73+
//console.log(old, '=>', r.request)
4974
},
5075
),
5176
)
52-
if (suffix === 'cjs.production.min.js') {
53-
config.resolve.mainFields = ['main', 'module']
77+
78+
if (suffix === 'production.min.cjs') {
79+
;(config.resolve ??= {}).mainFields = ['main', 'module']
5480
}
55-
config.optimization.nodeEnv = 'production'
81+
;(config.optimization ??= {}).nodeEnv = 'production'
5682
return config
5783
}
5884
}
@@ -66,42 +92,62 @@ const ignoreAll = [
6692
'redux-thunk',
6793
]
6894

69-
module.exports = [
95+
const entryPoints = [
7096
{
7197
name: `1. entry point: @reduxjs/toolkit`,
72-
path: 'dist/redux-toolkit.modern.js',
98+
path: 'dist/redux-toolkit.modern.mjs',
99+
},
100+
{
101+
name: `1. entry point: @reduxjs/toolkit/react`,
102+
path: 'dist/react/redux-toolkit-react.modern.mjs',
73103
},
74104
{
75105
name: `1. entry point: @reduxjs/toolkit/query`,
76-
path: 'dist/query/rtk-query.modern.js',
106+
path: 'dist/query/rtk-query.modern.mjs',
77107
},
78108
{
79109
name: `1. entry point: @reduxjs/toolkit/query/react`,
80-
path: 'dist/query/react/rtk-query-react.modern.js',
110+
path: 'dist/query/react/rtk-query-react.modern.mjs',
81111
},
82112
{
83113
name: `2. entry point: @reduxjs/toolkit (without dependencies)`,
84-
path: 'dist/redux-toolkit.modern.js',
114+
path: 'dist/redux-toolkit.modern.mjs',
115+
ignore: ignoreAll,
116+
},
117+
{
118+
name: `2. entry point: @reduxjs/toolkit/react (without dependencies)`,
119+
path: 'dist/react/redux-toolkit-react.modern.mjs',
85120
ignore: ignoreAll,
86121
},
87122
{
88123
name: `2. entry point: @reduxjs/toolkit/query (without dependencies)`,
89-
path: 'dist/query/rtk-query.modern.js',
124+
path: 'dist/query/rtk-query.modern.mjs',
90125
ignore: ignoreAll,
91126
},
92127
{
93128
name: `2. entry point: @reduxjs/toolkit/query/react (without dependencies)`,
94-
path: 'dist/query/react/rtk-query-react.modern.js',
129+
path: 'dist/query/react/rtk-query-react.modern.mjs',
95130
ignore: ignoreAll,
96131
},
97132
]
133+
134+
module.exports = entryPoints
98135
.flatMap((e) =>
99-
suffixes.map((suffix) => ({
136+
esmSuffixes.map((suffix) => ({
100137
...e,
101138
name: e.name + ` (${suffix})`,
102139
modifyWebpackConfig: withRtkPath(suffix),
103140
})),
104141
)
142+
.concat(
143+
entryPoints.flatMap((e) =>
144+
cjsSuffixes.map((suffix) => ({
145+
...e,
146+
name: e.name + ` (cjs, ${suffix})`,
147+
modifyWebpackConfig: withRtkPath(suffix, true),
148+
})),
149+
),
150+
)
105151
.concat(
106152
...[
107153
{
@@ -138,7 +184,7 @@ module.exports = [
138184
},
139185
].map((e) => ({
140186
...e,
141-
name: e.name + ` (esm.js)`,
142-
modifyWebpackConfig: withRtkPath('esm.js'),
187+
name: e.name + ` (.modern.mjs)`,
188+
modifyWebpackConfig: withRtkPath('modern.mjs'),
143189
})),
144190
)

packages/toolkit/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,7 @@ RTK Query includes these APIs:
104104
- `setupListeners()`: A utility used to enable refetchOnMount and refetchOnReconnect behaviors.
105105

106106
See the [**RTK Query Overview**](https://redux-toolkit.js.org/rtk-query/overview) page for more details on what RTK Query is, what problems it solves, and how to use it.
107+
108+
## Contributing
109+
110+
Please refer to our [contributing guide](/CONTRIBUTING.md) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Redux Toolkit.

0 commit comments

Comments
 (0)