Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reducerPath to extractRehydrationInfo #1645

Merged
merged 3 commits into from
Oct 25, 2021

Conversation

msutkowski
Copy link
Member

@msutkowski msutkowski commented Oct 24, 2021

  • Adds the ability for a consumer to have a little safety when setting up for SSR:
extractRehydrationInfo: (action, { reducerPath }) => {
    if (action.type === HYDRATE) {
      return action.payload[reducerPath];
    }
  },

In favor of #1643

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 24, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8d1996f:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration

@github-actions
Copy link

github-actions bot commented Oct 24, 2021

size-limit report 📦

Path Size
1. entry point: @reduxjs/toolkit (cjs.production.min.js) 12.28 KB (0%)
1. entry point: @reduxjs/toolkit (esm.js) 10.27 KB (0%)
1. entry point: @reduxjs/toolkit/query (cjs.production.min.js) 21.01 KB (+0.06% 🔺)
1. entry point: @reduxjs/toolkit/query (esm.js) 18.04 KB (+0.14% 🔺)
1. entry point: @reduxjs/toolkit/query/react (cjs.production.min.js) 23.09 KB (+0.05% 🔺)
1. entry point: @reduxjs/toolkit/query/react (esm.js) 20.71 KB (+0.13% 🔺)
2. entry point: @reduxjs/toolkit (without dependencies) (cjs.production.min.js) 5.6 KB (0%)
2. entry point: @reduxjs/toolkit (without dependencies) (esm.js) 5.58 KB (0%)
2. entry point: @reduxjs/toolkit/query (without dependencies) (cjs.production.min.js) 9.8 KB (+0.13% 🔺)
2. entry point: @reduxjs/toolkit/query (without dependencies) (esm.js) 10.23 KB (+0.17% 🔺)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (cjs.production.min.js) 2.63 KB (0%)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (esm.js) 2.47 KB (0%)
3. createSlice (esm.js) 5.16 KB (0%)
3. createEntityAdapter (esm.js) 5.83 KB (0%)
3. configureStore (esm.js) 5.83 KB (0%)
3. createApi (esm.js) 16.34 KB (+0.17% 🔺)
3. createApi (react) (esm.js) 18.97 KB (+0.12% 🔺)
3. fetchBaseQuery (esm.js) 10.98 KB (0%)
3. setupListeners (esm.js) 9.86 KB (0%)
3. ApiProvider (esm.js) 17.8 KB (+0.13% 🔺)

packages/toolkit/src/query/apiTypes.ts Outdated Show resolved Hide resolved
packages/toolkit/src/query/core/buildSlice.ts Outdated Show resolved Hide resolved
packages/toolkit/src/query/core/buildSlice.ts Outdated Show resolved Hide resolved
packages/toolkit/src/query/core/buildSlice.ts Outdated Show resolved Hide resolved
Co-authored-by: Lenz Weber <mail@lenzw.de>
((() => {}) as (a: AnyAction) => undefined)
const extractRehydrationInfo = defaultMemoize((action: AnyAction) =>
options.extractRehydrationInfo?.(action, {
reducerPath: (options.reducerPath ?? 'api') as any,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be done with:

type ReducerPathFromCreateApiOptions<
  Options extends CreateApiOptions<any, any, any, any>
> = Options extends CreateApiOptions<any, any, infer RP, any> ? RP : unknown

reducerPath: (options.reducerPath ?? 'api') as ReducerPathFromCreateApiOptions<typeof options>,

But I don't think there is any need to do that.

Copy link
Member

@phryneas phryneas Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's reaaaally not do that ^^

@phryneas phryneas merged commit 174c05a into feature/ssr-suspense Oct 25, 2021
@phryneas phryneas deleted the feature/ssr-suspense-patch-2 branch October 25, 2021 17:25
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.

2 participants