Skip to content

Commit 8fd3143

Browse files
committed
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit into configs
2 parents a23f410 + 75b4f69 commit 8fd3143

File tree

8 files changed

+255
-651
lines changed

8 files changed

+255
-651
lines changed

packages/toolkit/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reduxjs/toolkit",
3-
"version": "2.2.6",
3+
"version": "2.2.7",
44
"description": "The official, opinionated, batteries-included toolset for efficient Redux development",
55
"author": "Mark Erikson <[email protected]>",
66
"license": "MIT",
@@ -50,12 +50,15 @@
5050
},
5151
"devDependencies": {
5252
"@arethetypeswrong/cli": "^0.13.5",
53+
"@babel/core": "^7.24.8",
54+
"@babel/helper-module-imports": "^7.24.7",
5355
"@microsoft/api-extractor": "^7.13.2",
5456
"@phryneas/ts-version": "^1.0.2",
5557
"@size-limit/file": "^11.0.1",
5658
"@size-limit/webpack": "^11.0.1",
5759
"@testing-library/react": "^13.3.0",
5860
"@testing-library/user-event": "^13.1.5",
61+
"@types/babel__core": "^7.20.5",
5962
"@types/babel__helper-module-imports": "^7.18.3",
6063
"@types/json-stringify-safe": "^5.0.0",
6164
"@types/nanoid": "^2.1.0",
@@ -67,7 +70,7 @@
6770
"axios": "^0.19.2",
6871
"console-testing-library": "patch:console-testing-library@npm%3A0.6.1#~/.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch",
6972
"esbuild": "^0.23.0",
70-
"esbuild-extra": "^0.3.1",
73+
"esbuild-extra": "^0.4.0",
7174
"eslint": "^9.7.0",
7275
"eslint-config-prettier": "^9.1.0",
7376
"eslint-config-react-app": "^7.0.1",

packages/toolkit/src/configureStore.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import type {
3232
} from './tsHelpers'
3333
import type { Tuple } from './utils'
3434

35-
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
36-
3735
/**
3836
* Options for `configureStore()`.
3937
*
@@ -146,15 +144,22 @@ export function configureStore<
146144
)
147145
}
148146

149-
if (!IS_PRODUCTION && middleware && typeof middleware !== 'function') {
147+
if (
148+
process.env.NODE_ENV !== 'production' &&
149+
middleware &&
150+
typeof middleware !== 'function'
151+
) {
150152
throw new Error('`middleware` field must be a callback')
151153
}
152154

153155
let finalMiddleware: Tuple<Middlewares<S>>
154156
if (typeof middleware === 'function') {
155157
finalMiddleware = middleware(getDefaultMiddleware)
156158

157-
if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
159+
if (
160+
process.env.NODE_ENV !== 'production' &&
161+
!Array.isArray(finalMiddleware)
162+
) {
158163
throw new Error(
159164
'when using a middleware builder function, an array of middleware must be returned',
160165
)
@@ -163,7 +168,7 @@ export function configureStore<
163168
finalMiddleware = getDefaultMiddleware()
164169
}
165170
if (
166-
!IS_PRODUCTION &&
171+
process.env.NODE_ENV !== 'production' &&
167172
finalMiddleware.some((item: any) => typeof item !== 'function')
168173
) {
169174
throw new Error(
@@ -176,7 +181,7 @@ export function configureStore<
176181
if (devTools) {
177182
finalCompose = composeWithDevTools({
178183
// Enable capture of stack traces for dispatched Redux actions
179-
trace: !IS_PRODUCTION,
184+
trace: process.env.NODE_ENV !== 'production',
180185
...(typeof devTools === 'object' && devTools),
181186
})
182187
}
@@ -185,7 +190,11 @@ export function configureStore<
185190

186191
const getDefaultEnhancers = buildGetDefaultEnhancers<M>(middlewareEnhancer)
187192

188-
if (!IS_PRODUCTION && enhancers && typeof enhancers !== 'function') {
193+
if (
194+
process.env.NODE_ENV !== 'production' &&
195+
enhancers &&
196+
typeof enhancers !== 'function'
197+
) {
189198
throw new Error('`enhancers` field must be a callback')
190199
}
191200

@@ -194,19 +203,19 @@ export function configureStore<
194203
? enhancers(getDefaultEnhancers)
195204
: getDefaultEnhancers()
196205

197-
if (!IS_PRODUCTION && !Array.isArray(storeEnhancers)) {
206+
if (process.env.NODE_ENV !== 'production' && !Array.isArray(storeEnhancers)) {
198207
throw new Error('`enhancers` callback must return an array')
199208
}
200209
if (
201-
!IS_PRODUCTION &&
210+
process.env.NODE_ENV !== 'production' &&
202211
storeEnhancers.some((item: any) => typeof item !== 'function')
203212
) {
204213
throw new Error(
205214
'each enhancer provided to configureStore must be a function',
206215
)
207216
}
208217
if (
209-
!IS_PRODUCTION &&
218+
process.env.NODE_ENV !== 'production' &&
210219
finalMiddleware.length &&
211220
!storeEnhancers.includes(middlewareEnhancer)
212221
) {

packages/toolkit/src/createDraftSafeSelector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export const createDraftSafeSelectorCreator: typeof createSelectorCreator = (
2626
* @public
2727
*/
2828
export const createDraftSafeSelector =
29+
/* @__PURE__ */
2930
createDraftSafeSelectorCreator(weakMapMemoize)

packages/toolkit/src/listenerMiddleware/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const getListenerEntryPropsFrom = (options: FallbackAddListenerOptions) => {
221221

222222
/** Accepts the possible options for creating a listener, and returns a formatted listener entry */
223223
export const createListenerEntry: TypedCreateListenerEntry<unknown> =
224-
Object.assign(
224+
/* @__PURE__ */ assign(
225225
(options: FallbackAddListenerOptions) => {
226226
const { type, predicate, effect } = getListenerEntryPropsFrom(options)
227227

@@ -286,21 +286,29 @@ const safelyNotifyError = (
286286
/**
287287
* @public
288288
*/
289-
export const addListener = Object.assign(createAction(`${alm}/add`), {
290-
withTypes: () => addListener,
291-
}) as unknown as TypedAddListener<unknown>
289+
export const addListener = /* @__PURE__ */ assign(
290+
/* @__PURE__ */ createAction(`${alm}/add`),
291+
{
292+
withTypes: () => addListener,
293+
},
294+
) as unknown as TypedAddListener<unknown>
292295

293296
/**
294297
* @public
295298
*/
296-
export const clearAllListeners = createAction(`${alm}/removeAll`)
299+
export const clearAllListeners = /* @__PURE__ */ createAction(
300+
`${alm}/removeAll`,
301+
)
297302

298303
/**
299304
* @public
300305
*/
301-
export const removeListener = Object.assign(createAction(`${alm}/remove`), {
302-
withTypes: () => removeListener,
303-
}) as unknown as TypedRemoveListener<unknown>
306+
export const removeListener = /* @__PURE__ */ assign(
307+
/* @__PURE__ */ createAction(`${alm}/remove`),
308+
{
309+
withTypes: () => removeListener,
310+
},
311+
) as unknown as TypedRemoveListener<unknown>
304312

305313
const defaultErrorHandler: ListenerErrorHandler = (...args: unknown[]) => {
306314
console.error(`${alm}/error`, ...args)
@@ -350,7 +358,7 @@ export const createListenerMiddleware = <
350358
return insertEntry(entry)
351359
}) as AddListenerOverloads<any>
352360

353-
Object.assign(startListening, {
361+
assign(startListening, {
354362
withTypes: () => startListening,
355363
})
356364

@@ -378,7 +386,7 @@ export const createListenerMiddleware = <
378386
return !!entry
379387
}
380388

381-
Object.assign(stopListening, {
389+
assign(stopListening, {
382390
withTypes: () => stopListening,
383391
})
384392

packages/toolkit/src/query/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type {
4242
FetchArgs,
4343
} from './fetchBaseQuery'
4444
export { retry } from './retry'
45+
export type { RetryOptions } from './retry'
4546
export { setupListeners } from './core/setupListeners'
4647
export { skipToken } from './core/buildSelectors'
4748
export type {

packages/toolkit/src/query/react/ApiProvider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { configureStore } from '@reduxjs/toolkit'
22
import type { Api } from '@reduxjs/toolkit/query'
33
import { setupListeners } from '@reduxjs/toolkit/query'
44
import type { Context } from 'react'
5-
import React, { useContext, useEffect } from 'react'
5+
import { useContext } from 'react'
6+
import { useEffect } from 'react'
7+
import * as React from 'react'
68
import type { ReactReduxContextValue } from 'react-redux'
79
import { Provider, ReactReduxContext } from 'react-redux'
810

packages/toolkit/tsup.config.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export default defineConfig((options) => {
183183

184184
if (env) {
185185
Object.assign(defineValues, {
186-
'process.env.NODE_ENV': JSON.stringify(env),
186+
NODE_ENV: env,
187187
})
188188
}
189189

@@ -203,15 +203,8 @@ export default defineConfig((options) => {
203203
sourcemap: true,
204204
external: externals,
205205
esbuildPlugins: [mangleErrorsTransform],
206-
esbuildOptions(options) {
207-
// Needed to prevent auto-replacing of process.env.NODE_ENV in all builds
208-
options.platform = 'neutral'
209-
// Needed to return to normal lookup behavior when platform: 'neutral'
210-
options.mainFields = ['browser', 'module', 'main']
211-
options.conditions = ['browser']
212-
},
213206

214-
define: defineValues,
207+
env: defineValues,
215208
async onSuccess() {
216209
if (format === 'cjs' && name === 'production.min') {
217210
await writeCommonJSEntry(outputFolder, prefix)
@@ -247,7 +240,7 @@ export default defineConfig((options) => {
247240
// fs.copyFileSync(inputTypedefsPath, outputTypedefsPath)
248241
}
249242
},
250-
}
243+
} satisfies TsupOptions
251244
})
252245

253246
return artifactOptions satisfies TsupOptions[]

0 commit comments

Comments
 (0)