Adding non-serialisable metadata to toState
See original GitHub issueThis is a follow up of https://github.com/router5/router5/issues/60#issuecomment-233296870
@troch I’m hitting the issue that @iotch mentioned… I would like to attach non-serializable stuff into toState
:
// getComponentMiddleware.js
export default (routes) => (router) => (toState, fromState) => {
const { toActivate } = transitionPath(toState, fromState);
// Get the routes involved in the transition
const routesToActivate = toActivate.map((segment) => routes.find((route) => route.name === segment));
// Build a map in which keys are the route names and values that resolve to their components
const promisesMap = fromPairs(routesToActivate.map((route) => [route.name, route.component || route.getComponent()]));
return pProps(promisesMap)
.then((components) => ({ ...toState, components }));
};
DOMException: Failed to execute 'pushState' on 'History': An object could not be cloned.
So here are a few questions:
- Do we really have to persist the state to the history api?
browser.getState
is only used here. Isn’t it more correct to compare the URLs instead of comparing states? In my opinion, the browser plugin is just a way to set and react to URL changes, it shouldn’t be storing nor handling states. Also, this would remove the inconsistency that exists now between using history API or hashbangs. - If you would like to keep it like this, could we have field that would not be included in the history state? This would allow us to add big data structures (big structures generate QUOTA errors) or unserializable data to be added to
toState
.
Thanks in advance.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Java: What can and what can't be serialized? - Stack Overflow
First of all, if you don't plan to ever serialize an instance of your class, there is no need to even think about...
Read more >The redux best practice "Do Not Put Non-Serializable Values ...
This article explains one of the four react-redux best practices: "Do Not Put Non-Serializable Values in State or Actions"
Read more >NonSerializedAttribute Class (System) - Microsoft Learn
Indicates that a field of a serializable class should not be serialized. This class cannot be inherited.
Read more >R Packages (2e) - 10 DESCRIPTION
The DESCRIPTION file provides overall metadata about the package, such as the package name and which other packages it depends on. The NAMESPACE...
Read more >Bug? Why doesn't JSON.serialize support ...
As of API v42.0 this is still not fixed. While serializing in the Dev Console works fine calling the code from a trigger...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@satazor this has been fixed with v4.7.1: only base state properties (
meta
,name
,path
andparams
) are pushed to history.Yes. I think the best is to allow the user to customize entirely the way the state is stored with simple options. I think something in the spirit of
react-redux
could be suitable:mapRouterStateToBrowserState
andmapBrowserStateToRouterState
can both default to an identity function,s => s
. This is not breaking changes.