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

make it easier to disable has history query key #47

Closed
eknuth opened this issue Sep 11, 2015 · 8 comments
Closed

make it easier to disable has history query key #47

eknuth opened this issue Sep 11, 2015 · 8 comments

Comments

@eknuth
Copy link
Contributor

eknuth commented Sep 11, 2015

I'm using history in conjunction with react router and redux router. With this setup there is no way to set the queryKey option to false. I'm consistently blowing up my session storage quota.

To initialize the redux router you pass the createHistory function as an argument. createHistory is then called by react router with the default option for queryKey.

I realize this issue has more to do with how these three project are used together, but I figured I would start here.

@mjackson
Copy link
Member

I'm consistently blowing up my session storage quota.

How will disabling the hash history query key help you with that?

@acdlite
Copy link
Contributor

acdlite commented Sep 11, 2015

For a fix to your specific problem, you can also pass history to reduxReactRouter() rather than createHistory(). I'm going to try to mirror the <Router> API as best as I can.

Or you could do what React Router does and pass () => createHistory(options) as your createHistory() function.

https://github.com/rackt/react-router/blob/master/modules/Router.js#L49

I agree that it's a bit weird that useRouting() is a history enhancer (which operates on createHistory()) but the API for configuring the Router involves passing a history object.

This thread probably belongs over at React Router.

@eknuth
Copy link
Contributor Author

eknuth commented Sep 11, 2015

@mjackson From the hash history caveats I was under the impression that this option would disable the persistent state storage. I'm seeing a different value for _k every time I push or replace state, though.

@acdlite I appreciate your quick response. Should I take this to react router, or redux router?
Unfortunately giving reduxReactRouter an instance of history, or a function that returns an instance doesn't seem to work. :(

let createHistory = (opts) => {
  return createHashHistory({queryKey: false})
}

let reduxRouter = reduxReactRouter({
  routes: routes,
  createHistory: createHistory
})

In my logs I see:

Warning: Failed propType: Required prop `location` was not specified in `RoutingContext`. Check the render method of `ReduxRouterContext`.
warning.js:48 Warning: Failed propType: Required prop `routes` was not specified in `RoutingContext`. Check the render method of `ReduxRouterContext`.

I appreciate the quick response, guys. Thanks!

@eknuth eknuth closed this as completed Sep 11, 2015
@amccloud
Copy link

@eknuth what did you end up doing about the storage quota?

To disable queryKey I ended up doing:

function useNoQueryKey(createHistory) {
  return function(options={}) {
    options.queryKey = false;
    return createHistory(options);
  };
}

export default reduxReactRouter({
  createHistory: useNoQueryKey(createHashHistory),
  routes
});

@mjackson is it safe to disable queryKey if you never pass state to the navigation APIs? Would it behave like the old HashHistory in react-router?

@eknuth
Copy link
Contributor Author

eknuth commented Sep 21, 2015

@amccloud I ended up not disabling the queryKey for history. We just stopped pushing all of our state in the router actions. When you push or replace, the first argument can be an empty string.

@NeXTs
Copy link

NeXTs commented Nov 9, 2015

@eknuth You can disable the queryKey this way

import createHistory from 'history/lib/createHashHistory';
...


reduxReactRouter({
  routes: routes,
  createHistory: (options) => createHistory(Object.assign({queryKey: false}, options))
})

The only disadvantage is that it logs warnings to console, although seems it will resolved soon too.
acdlite/redux-router#136

@timaschew
Copy link

How can I turn if off for 'history/lib/createBrowserHistory' ?

@mjackson
Copy link
Member

mjackson commented Jan 4, 2016

See #163

It's not super high priority though because hash history is really only for older browsers.

@remix-run remix-run locked and limited conversation to collaborators Jan 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants