-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): Main process can save slices of state & worker can access it #31822
Conversation
@@ -83,15 +84,19 @@ export const configureStore = (initialState: IGatsbyState) => | |||
) | |||
|
|||
export type GatsbyReduxStore = ReturnType<typeof configureStore> | |||
export const store: GatsbyReduxStore = configureStore(readState()) | |||
export const store: GatsbyReduxStore = configureStore( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that the worker doesn't load the persisted state by default
export function readFromCache(): ICachedReduxState { | ||
export function readFromCache( | ||
slices?: Array<GatsbyStateSlices> | ||
): DeepPartial<ICachedReduxState> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the results for workers (using the slices) won't be the complete state I had to use DeepPartial
in some places of this file
packages/gatsby/src/redux/types.ts
Outdated
@@ -320,6 +320,8 @@ export interface IGatsbyState { | |||
} | |||
} | |||
|
|||
export type GatsbyStateSlices = keyof IGatsbyState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives you autocomplete for e.g. ['components', 'staticQueryComponents']
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is a bit weird IMO. GatsbyStateKeys would be better. I read it as it's a partial piece of state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, naming change done in af20d74
The failing integration tests for CLI will be fixed by https://github.com/gatsbyjs/gatsby/pull/31773/files#diff-d22c422fe2fd6cfd9f0dae18012aa9cbe960ac2adcc9c6b95b557c78d7f3490c See #31848 |
115ceab
to
05c6cea
Compare
Description
In order to save certain parts (slices) of the internal redux store and make it accessible in workers I've added two helper functions called
saveStateForWorkers
andloadStateInWorker
. They reuse the existingreadFromCache
andwriteToCache
functions.Since we now also store parts of the Gatsby State inside redux I had to change some TS typings to move from
IGatsbyState
toDeepPartial<IGatsbyState>
Related Issues
[ch32396]