-
-
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
v2 Roadmap #2646
Comments
Do you guys have some code to push so we can see where you're at and where we can help? You have the advantage of being in person, so your cycle times are much lower, but d be happy to help with any menial changes that need to be made. |
I don't think @mjackson has internet on his flight home from London, I'll probably have some code to push by the end of my flight. And then others can poke the code and see if it works as we'd like it to. |
Just some thoughts/feedback now that I've had a chance to read through all of this:
I think, for the sake of making the upgrade less painful for hash users, we should leave it in the repo, but not export it. Users that need it still have a one-liner to access it, but we also don't increase bundle size. It can be explicitly deprecated for removal in a 2.x release.
Could we add
Given how simple this is, I think we should bundle it into the library. Then I can throw
I think that will actually end up looking like this (provided with a good render((
<Router render={compose(
renderAsyncProps,
renderRelayRoutes,
renderScrollRestorer,
)}>
), el) You can just bump up the order of the Overall, this looks great. There's a trend towards increasing userland code with this route, but I don't think it's all that terrible and really only affects those doing more eccentric things with the router. |
💯 on this, this is fantastic. Have a few minor comments/notes but will write them up later. |
1.0.0 API will work in 1.1.0, so upgrading should be "drop-in but now you have warnings". So yeah, we'll still have a default but with a warning. |
Nope, React 15 or 16 won't let us, reread the issue :P Also, history is not going to be router API anymore. If you need your history, your app will have the object it passed to router, just import it and use it wherever, you don't need it in the render tree. |
Another great reason not to have it in the package :P We've never wanted to be in the "mixins v. decorators" business and now that context is documented we don't have to be. |
I meant having history as a property next to push and replace and all that jazz. But you're right, hence my ambivalence 😄 |
I would personally do the component version not the compose version, and since the compose version can be built on top of the component version, we'd keep with our philosophy of "building the lower-level thing and letting apps get opinionated about [stuff]" |
:D 💃 That's exactly the goal, thanks for considering all of this. We'll do our best to get some code up for everybody to help us fix soon. |
Any love for #2186 in v1.1.0? :) |
@bjrmatos There's some support work on history for that first. Then it can be implemented on router. But it's independent of the changes here. |
Okay, got back to my computer. Some more detailed thoughts:
<Router render={props => (
<RelayWrapper {...props} />
<SomeOtherWrapper {...props} />
<RoutingContext {...props} />
</SomeOtherWrapper>
</RelayWrapper>
)} /> But as noted, this is all in userspace anyway, so users can do whatever they want. Overall, I'm 100% behind this. This is really fantastic, @ryanflorence. |
@ryanflorence Yes, but this is about moving that API, not necessarily changing its signature. We can certainly do it at the same time, but it's not a requirement for this issue to close. |
@taion I like that form of render even more! I was in FP mode in my head, so I forgot about props.children. That reads a lot better without having to layer on additional functional concepts. |
Yeah, the main thing is that "what users choose to do" shouldn't affect our choice of API here - we don't have any control over the patterns they use. For me, I'm probably going to keep just exposing |
On terminology - for the pushable locations, do you like the term "location descriptor"? I have it written up as "location spec" in my in-progress docs for the corresponding changes on |
@taion The only gotcha is we can't enforce using children, so that kind of composition can break down if a render wrapper doesn't expect them. We should document whatever form we choose so that the pattern and use cases for it are known. |
What about just calling it a capital L "Location"? |
@knowbody Thanks. Sorry for the noob question. |
Please provide a document about how to write a middleware component. const createElement = (Component, props) => {
// How to handle Middleware1Container and Middleware2Container
};
...
ReactDOM.render(
<Router routes={routes}
history={history}
createElement={createElement}
render={props => (
<Middleware1 {...props} render={props => (
<Middleware2 {...props} render={props => (
<RouterContext {...props}/>
)}/>
)}/>
)}/>,
document.getElementById('app')
); |
So, at the moment the It'd be really useful to be able to introspect the matched route and navigate to its parents (e.g. I set an extra It's super hacky, awkward code at the moment because there isn't really a nice way to (eg) inherit a default title. |
Keep in mind that a route is normally comprised of a nested set of routes. When we pass along You can also get access to |
Right - it works nicely from the component. The awkwardness in this situation comes from the router only rendering the Being able to get the |
I could also use a static property (global variables, yay) - except that that's a race condition waiting to happen on the server. EG:
|
I think you mis-read. Those are available. They're at |
Ahh, I understand now. I was confused when inspecting it because the first one was the root route (so looked like a complete list of routes. |
This issue's description has following: // v2.0.0
class RouteComponent extends React.Component {
someHandler() {
this.props.router.push(...)
}
} which should be: // v2.0.0
class RouteComponent extends React.Component {
someHandler() {
this.context.router.push(...)
}
} Also, v2.0.0 Upgrade Guide doesn't seem to have instructions given here in Lifecycle Mixin with deep, non-route components section. I will send a PR if needed for the same. Beside, I am really happy to see this terrific work on v2.0. A big "Hi, Five!" to the React Router team. |
Hey all, not sure if this is the right place for a v2 bug, but with { __esModule: true,
// ...
browserHistory: undefined,
hashHistory: undefined,
// ...
} |
They are in fact exported properly – double check your setup. |
OK, can you offer a baseline to work from? I was using node 4.0.0 before, but I just tried upgrading to node 5.5.0, npm 3.5.3. I did a clean sweep in a new project, |
Any idea what should be done as a fix for scroll-behavior for the time being? |
@mjackson just pushed history 2.0.0-rc3 (Thanks, Michael! 🤘), so I think we're all good here. @ryanflorence Can you push out a 2.0.0-rc6 to suss out any final bugs? We can go 2.0.0 final soon afterwards 😄 |
You probably shouldn't publish prereleases or rcs as the |
@timoxley That was fixed over here. It probably just needs to be applied to NPM as well. |
Testing the rc5 now and using the |
@tleunen It's right in the upgrade guide: https://github.com/rackt/react-router/blob/master/upgrade-guides/v2.0.0.md#using-custom-histories |
Is there a publicly viewable version of the full docs updated for 2.0 public yet? I'm aware of the 2.0 upgrade guide. Is that (and this thread) still the sole docs for 2.0? |
The docs on master are for 2.0. |
Coming from the redux-router-react discussion and switch to react-router 2.0 only for now. My 2 cts experience for the repo: hard to be sure if the master is the V2. The npm version is confusing. |
Guess we can close this... 😄 |
This might not be the best way to manage this (one gigantic issue), but @mjackson and I are a solid 50% done with all of this anyway, so I'm not too concerned.
@taion you'll likely have some questions since this affects a lot of what you're trying to do, please chat me up on discord before we clog up this issue with back-and-forth conversation :)
Router 2.0 Roadmap
TOC
useRoutes
router
render
propMotivations for the following API changes are all about cleaning up and clarifying the coupling between React Router and History; this generally translates to "You won't need to know anything about History anymore."
The following issues should help address these concerns.
Note about upgrading
All v1.0.0 APIs will continue to work in v2.0.0. An app using only public API should be able to drop in v2.0.0 and just get warnings. Old API will be removed in 3.0.0. If you update your code and no longer get warnings, you should be able to upgrade to 3.0 w/o trouble.
Ship History 2.0
It's really just removing deprecated API. The rest of these items all kind of depend on it though.
Refactor route matching out of
useRoutes
and intomatch
Background
Currently we wrap a history with
useRoutes
so it is now aware of routes and performs the match against them. This changes the signature and timing oflisten
(making it async) causing difficulty when integrating or using alongside libraries like redux and react native.Additionally, navigating outside of components (like in flux and redux) is complicated by
Router
wrapping the history provided as a prop.Goals
listenRoutes
to integrate with other libsuseQueries
in order to navigate outside of components(custom queryString parsing, etc.) and
Router
should not touch thehistory provided
Upgrading
Tasks
While the nitty gritty won't be this simple, this is what will probably need to happen:
useRoutes
and move all route matching tomatch
match
inside ofRouter
instead of wrapping the history provided in anything (don't alter history)hashHistory
andbrowserHistory
singletons, exported fromindex.js
hashHistory
and require devs to provide one, should help with people not understanding that there's a better option, and allow devs to decrease the bundle size of their appExport only
router
to contextBackground
Right now we put
history
,location
, androute
(sometimes) on context, we also pass a bag of props to route components. Turns out there's some overlap between them. We're tempted to add more to context, and add more to props because the line and purpose between them isn't clear.React Router continues to strive to be just one library in a wonderful ecosystem of other libraries, prescribing strategies for data flow in an app is not our goal. We will put only what we absolutely need in context (which can be summed up with "what does
Link
need?). Everything else will go to route components as props. The opinions of the app can take over from there.Context was recently documented, so we no longer need the mixins to hide the context API. It's up to the app to decide if it wants to use context directly or continue to hide it with mixins or higher order components.
Also, react 15 or 16 will only allow one
contextType
. We've been talking about only have one context type for a while. Now is the time.Finally, in the global effort to make History an implementation detail, we need to provide something else to navigate around in components.
Goals
Tasks
Deprecate all items on context:
history
,location
,route
Add
context.router
that looks like this:Pass
router
as a prop to route componentsDeprecate all mixins
Deprecate passing
history
to route componentsproxy push/replace/isActive/addRouteLeaveHook to underlying history (so integration with a custom
history
will work)automatically remove route leave hooks since we should know everything we need to know, so devs don't have to and there's no reason to leave them hanging around.
Upgrading
History methods
In all cases where you once had a
history
for navigation, you now have arouter
with different methods.Navigating in route components
Navigating inside deeply nested components
Lifecycle Mixin with route components
Lifecycle Mixin with deep, non-route components
Add
render
prop toRouter
, removeRoutingContext
propBackground
The functional composition of
history
is awesome, but we also need this kind of composition for React Router when it's time to render. While we can add some behavior intohistory
we lack the necessary lifecycle hooks that components give us. Integrations also need all of the routing information in aggregate (like all the components and routes).Our current workaround is the
RoutingContext
prop, but that only lets us add one level of behavior. Consider an app that was built with Async Props, but now wants to iterate to using Relay, as well as add a new scroll restoring behavior. If each of these components used theRoutingContext
prop API, they would all render aRoutingContext
and therefore can't be used together.Goals
Upgrading
Tasks
RoutingContext
prop, no need for deprecation warnings, it's undocumented and everybody we've told to try it got an earful of "we aren't sure about this thing yet"render
prop toRouter
RoutingContext
props
in a method calledrender
Holy smokes that looks like a lot, it's really not too much, and we're feeling really good about it all.
The text was updated successfully, but these errors were encountered: