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 match set the location as history entry when creating new memory history object #3394

Closed
wants to merge 3 commits into from

Conversation

denvned
Copy link

@denvned denvned commented Apr 27, 2016

I believe, this is a proper fix for denvned/isomorphic-relay-router#26.

@@ -20,7 +20,7 @@ function match({ history, routes, location, ...options }, callback) {
'match needs a history or a location'
)

history = history ? history : createMemoryHistory(options)
history = history || createMemoryHistory({ entrires: [location], ...options })
Copy link

Choose a reason for hiding this comment

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

typo in entries

Copy link
Author

Choose a reason for hiding this comment

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

Fixed. Thanks!

@taion
Copy link
Contributor

taion commented Apr 27, 2016

This was previously rejected as #3089. We explicitly don't want to set the history location here – the history should be treated as a stateless (and potentially reusable) object that otherwise holds no state.

@taion taion closed this Apr 27, 2016
@denvned
Copy link
Author

denvned commented Apr 27, 2016

the history should be treated as a stateless (and potentially reusable) object that otherwise holds no state.

@taion, But this PR code does not change state of the history, it only provides the location to createMemoryHistory. Without that, createMemoryHistory defaults location to some meaningless value (/)... I really don't understand why the latter is considered correct behaviour, and why I should use hacks like https://github.com/denvned/isomorphic-relay-router/blob/v0.7.0-beta.1/src/prepareData.js#L6-L7.

@timdorr
Copy link
Member

timdorr commented Apr 27, 2016

I'm with @denvned here. The history isn't stateless by default and that is causing issues for people that assume the defaults are consistent (they are not).

@taion
Copy link
Contributor

taion commented Apr 27, 2016

Can you clarify how this is coming up? I don't think user code on the SSR path should be touching the history at all, beyond using it to create hrefs if needed.

@timdorr
Copy link
Member

timdorr commented Apr 27, 2016

It's not directly. It's touching router from renderProps. Here's something that could be turned into a breaking case:

match({ routes, location: '/test' }, function (error, redirectLocation, renderProps) {
  renderProps.router.listen(loc => expect(loc.pathname).toEqual('/test')) // Fails. This equals '/'
})

@taion
Copy link
Contributor

taion commented Apr 27, 2016

I think that, when rendering on the server, you should not be able to call listen, push, or replace with the implicit history-like-object that we create.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants