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 section to usage guide on working with non-serializable data #623
Conversation
…updates error message in serializableStateInvariantMiddleware to link to new section in usage guide
Deploy preview for redux-starter-kit-docs ready! Built with commit 7755ffb https://deploy-preview-623--redux-starter-kit-docs.netlify.app |
So, there's a number of failing tests on master. About 10 tests fail, all look like this:
My changes have nothing to do with that, so I'm unsure how to proceed. |
Hmm. Looking at build failures listed in Travis, they specifically seem to be about the snapshots for the serializability middleware. Not immediately seeing any TS-related issues. |
Also, why is that "fixes" commit full of formatting changes? Are we flip-flopping Prettier versions between people's installs or something? |
I wish I could tell you. I've run |
Also, I updated the snapshots, but I have no idea why the tests aren't passing in travis. The only tests that don't pass for me locally are the ones I mentioned earlier. This repo just isn't behaving as I would expect it to and I don't have the time to figure it out. Feel free to take the changes from my commits and adding them in a different PR. |
There was a rogue space. I pushed a fix, let's see if it works now. Edit: rather than that, it was missing - which makes my commit message nonsensical. Oh well, it's getting squashed away anyways :D |
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 7755ffb:
|
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 reads nicely and is good for covering actions that a lot of 3rd party libraries dispatch 👍 .
My only other thought is that we should consider addressing 'What to do if a 3rd party redux library inserts non-serializable data into your store'. In that case, they'd want to leverage ignoredPaths
. Currently, it's usage is pretty opaque, but can be figured out.
Here is a quick draft of that idea:
Handling non-serializable data in an action
... original stuff
Handling non-serializable data in your store
In the instance that a 3rd party library is inserting non-serializable data into your store and you're unable to have this resolved with the library author, you can work around this by using the ignoredPaths
property when configuring the store.
configureStore({
//...
middleware: getDefaultMiddleware({
serializableCheck: {
ignoredPaths: ['reducerKey'] // would target `state.reducerKey` and all of it's children
}
})
})
I think we at least ought to have a specific example of setting up with Redux-Persist, because A) it's a legit example of customizing the behavior, and B) it's come up fairly frequently in the issues. (Also maybe React-Redux-Firebase, if there's anything relevant there?) |
@markerikson There for sure is with Either way, an example of the configuration needed for those libs looks like this: import {
configureStore,
getDefaultMiddleware,
} from "@reduxjs/toolkit";
import {
getFirebase,
actionTypes as rrfActionTypes,
} from "react-redux-firebase";
import { constants as rfConstants } from "redux-firestore";
import rootReducer from "./rootReducer";
import { useDispatch } from "react-redux";
const extraArgument = {
getFirebase,
};
export type DefaultThunkExtra = typeof extraArgument;
const middleware = [
...getDefaultMiddleware({
serializableCheck: {
ignoredActions: [
// just ignore every redux-firebase and react-redux-firebase action type
...Object.keys(rfConstants.actionTypes).map(
(type) => `${rfConstants.actionsPrefix}/${type}`
),
...Object.keys(rrfActionTypes).map((type) => `@@reactReduxFirebase/${type}`),
],
ignoredPaths: ["firebase", "firestore"],
},
thunk: {
extraArgument,
},
}),
] as const;
const store = configureStore({
reducer: rootReducer,
middleware,
});
export type AppDispatch = typeof store.dispatch;
export const useAppDispatch = () => useDispatch<AppDispatch>();
export default store; Note: there is more typing that needs to be done specifically for the reducers they ship to be TS compatible with RTK, but is probably a separate issue. I haven't seen many people mention that, but a PR I had opened for the problem is hopefully getting merged in their 3.6 release Looking at that, we should probably add another property of |
I'll go ahead and merge this, and do some more edits on the docs content from there. Thanks! |
Adds