Skip to content

Commit bec3fa7

Browse files
authored
Merge pull request #2062 from reduxjs/pr/exports-rsc
2 parents acb455c + 58296db commit bec3fa7

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"./package.json": "./package.json",
2020
".": {
2121
"types": "./dist/react-redux.d.ts",
22+
"react-server": "./dist/rsc.mjs",
2223
"import": "./dist/react-redux.mjs",
2324
"default": "./dist/cjs/index.js"
2425
},

src/index-rsc.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type * as normal from './index'
2+
import type * as rsc from './index-rsc'
3+
4+
// checks to make sure we didn't forgot to replicate any exports
5+
6+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7+
const _check: typeof normal = {} as typeof rsc
8+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9+
const _check2: typeof rsc = {} as typeof normal
10+
11+
// -------------------------------------------------------------------------------------
12+
13+
function throwNotSupportedError(
14+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
15+
...args: any[]
16+
): any {
17+
throw new Error(
18+
'This function is not supported in React Server Components. Please only use this export in a Client Component.'
19+
)
20+
}
21+
22+
export {
23+
throwNotSupportedError as batch,
24+
throwNotSupportedError as Provider,
25+
throwNotSupportedError as connect,
26+
throwNotSupportedError as useSelector,
27+
throwNotSupportedError as useDispatch,
28+
throwNotSupportedError as useStore,
29+
throwNotSupportedError as createDispatchHook,
30+
throwNotSupportedError as createSelectorHook,
31+
throwNotSupportedError as createStoreHook,
32+
}
33+
export const ReactReduxContext = {} as any
34+
export { default as shallowEqual } from './utils/shallowEqual'

tsup.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ export default defineConfig((options) => {
3434
dts: true,
3535
clean: true,
3636
},
37+
// ESM for RSC
38+
{
39+
...commonOptions,
40+
entry: {
41+
rsc: 'src/index-rsc.ts',
42+
},
43+
format: ['esm'],
44+
outExtension: () => ({ js: '.mjs' }),
45+
dts: false,
46+
},
3747
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
3848
{
3949
...commonOptions,

0 commit comments

Comments
 (0)