-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Migrate router and <app-view> to React #4525
Conversation
I'm not sure we should keep this pattern. It's probably better to handle the load lifecycle in the page component itself.
Also not sure this worth implementing. We will need to do some extra work if we don't, but will end up with a "cleaner" and more explicit solution. But we can start with both implemented (specially considering you already done the resolve) as a crutch to help with move the migration forward and once everything is working, make another PR that removes each of them and replaces it with better pattern. |
@arikfr Implementing both features is not that hard (as you mentioned, I already implemented |
61fbc54
to
b4ff41c
Compare
a65f5f5
to
933b50a
Compare
e9a3311
to
6e8872c
Compare
@gabrieldutra Fixed 👍 I also refined code a bit, so please review it as well. Thank you! |
render: currentRoute => ( | ||
<AuthenticatedPageWrapper key={currentRoute.key}> | ||
<ErrorBoundaryContext.Consumer> | ||
{({ handleError }) => <DashboardPage {...routeParams} onError={handleError} />} | ||
{({ handleError }) => <DashboardPage {...currentRoute.routeParams} onError={handleError} />} | ||
</ErrorBoundaryContext.Consumer> | ||
</AuthenticatedPageWrapper> | ||
), |
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.
Not sure if it's that worth it at this point, but it looks like pages follow the same pattern when being defined, if this is not intended to be changed (and every page should follow this notation), we perhaps could abstract it a bit more with a closure returning this function? (seems we can tweak it to receive only the page component and some extra routeParams):
{
path: "/dashboard/:dashboardSlug",
render: authenticatedPage(DashboardPage, { extraData: "dashboard-page" }),
}
BTW, if I had to choose, I think it's better to pass routeParams
as separate props (like you did to List Pages) and not directly to the props (I don't know, but it feels risky to me to leave props that open 😬).
Well, lmk your opinion
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.
- Yes, indeed it makes sense. But let's do it in a follow-up PR - I don't want to add anything more to this one (except of bug fixes related to PR's subject);
- With new router it's safe to spread route params - that object contains only values from URL (in this example -
dashboardSlug
) and resolved values (which will be removed soon), Router does not add anything to it (unlike Angular's router which was merging params from URL, resolved values and query string params).
|
||
useEffect(() => { | ||
if (bodyClass) { | ||
document.body.classList.toggle(bodyClass, true); |
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.
(Not blocking; just to understand if we can improve this further on)
Do we really need to set this class on the body
element instead of one of the children that we can control w/ React?
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.
ATM - yes, because it stretches few wrapper components when that class is set. To avoid this, we have to revisit some layout styles which I didn't want to do in this PR.
path: "/alerts/:alertId([0-9]+)/edit", | ||
title: "Alert", | ||
render: currentRoute => ( | ||
<AuthenticatedPageWrapper key={currentRoute.key}> |
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.
Why do we need to duplicate this piece of logic (AuthenticatedPage + ErrorBoundry) on every page?
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.
Also, passing handleError
to every page feels like too much. Can't we solve this with some global state/context?
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.
As I mentioned in reply to @gabrieldutra, I'm going to revisit this and few other things in a follow-up PR; currently it's stable, and I prefer not to add any more changes to this PR.
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.
Also, passing handleError to every page feels like too much. Can't we solve this with some global state/context?
Yes, and that's what I plan to do. There is a context already though; it's easy to use it with function-based components and a bit trickier with class-based ones - I didn't want to deal with it now so just passed it as a prop everywhere.
querySnippetsRoutes, | ||
organizationSettingsRoutes, | ||
usersListRoutes, | ||
userProfileRoutes, |
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.
👍 good find.
Not something to spend on time now, but it's interesting to see how Next.js handles this. Because they have dynamic imports and produce optimized builds.
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.
One thing I noticed which is broken:
- Start a new query.
- Execute.
- Click on New Visualization.
Unlike before, it's not saved and you can't save the viz.
@arikfr Seems it was broken during Query pages migration (I reproduced it on |
Here's another one:
You get every parameter update added to the history so going back feels like it's not working (you need to click lots of time until you get back to the homepage). |
62e2cc6
to
9d00be5
Compare
9d00be5
to
f8e7334
Compare
I triggered another build. |
@arikfr That test was still not stable even after my previous fix; new fix worked fine on my PC, need to try on CI now. A short explanation about history bloating bug fix: the actual issue is in Also, while reproducing this bug on |
ff4e311
to
7e3f9cf
Compare
🙌 |
Congrats!! |
What type of PR is this? (check all applicable)
Description
angular-router
withuniversal-router
+history
universal-router
+history
;route.resolve
map in the same manner asangular-router
does;<a>
tags globally similarly to whatangular
does.<app-view>
component to Reactng-app
directive.$route
/$routeParams
services;$location
service.Related Tickets & Documents
React migration #3071, closes #4159.
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
No UI changes