-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Fix lifecyle method workarounds #2378
Conversation
When you say |
No, I was talking about the |
Makes Discussion Page route work without diffing.
Ready for review. I removed a bunch of stuff in discussion page to make it work, but couldn't find any bugs or difference in behavior resulting from that. |
I'll reply more in depth tomorrow, but I have some concerns about this approach:
That being said, I don't love what we have now either, and there's a lot of issues with the PR for a cleaner API for the current system (the oncreate thing, for instance. We'd need to have another overridable method for oncreate stuff that should be executed onNewRoute. |
Regarding the links, I was thinking about making the force attribute the default if we're fully re-rendering the routes either way.
https://mithril.js.org/route.html#key-parameter Based on that it seems to be also possible to have route resolvers fully re-render the page. Let me check. |
New approach uses now again route resolvers, and removes the need for |
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.
Thank you so much for working on this, it's a LOT nicer than the current implementation. I still need to try it out locally, but if it works, I think we should include this in beta 14.
Are we leaving the force parameter and setRouteWithForcedRefresh so that a full rerender can be done while on the same page? (e.g. for LinkButtons on IndexPage or the logo/home link in the navbar?) Also, if we're switching to this system, perhaps LinkButtons should have force set to true by default (I don't think that would break anything). That further minimizes changes in behavior from beta 13
I think we could remove the |
We'll want to keep those so that we can force rerender index page by clicking the logo/forum name. We might also want to add force=True to LinkButtons by default, that way we keep the behavior of refreshing the index page by clicking LinkButtons in nav. |
Yes, what I wanted to say is that I think we might need a different solution to fix that. If I go https://nightly.flarum.site and click the home link it doesn't refresh the page for me, when I'm already on the '/' route. |
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.
Tested locally, haven't encountered any issues. Also, this implementation has turned out to be very clean, thanks for working on this!
For the link, frankly, this looks like another thing (accidentially perhaps) fixed by this PR: locally, setRouteWithForcedRefresh doesn't work, but on your branch it does. Let's keep the |
I've split off the Link stuff into a new PR: #2382 |
Before we merge this in, I played around with the route resolver system a bit, and was able to recover functionality for scrolling from one post to another while on the same discussion page if changing URL via I've put the new mapRoutes in https://hastebin.com/ikidecawuv.js If we include that in this PR, we fully retain that behavior from beta 13, which means less work for extensions (and also cleaner code imo) |
I think if we want to preserve that, we could abstract it into a Page |
I agree with that line of thinking, but not sure about placing it in Page. We'd need to use a static method, called from the route resolver. I'm hoping to replace the route resolver in
I started with that (introducing a util to make things simpler), but it still led to very messy code. In some cases (read: mentions), we just have a post number/ID, and we don't want to unnecessarily load in stuff from the API, so we need duplicate logic there. In other cases (read: notifications), all we have is a url, so we'd need to parse that out and match it. It's small changes, but they're messy code-wise (a lot of |
Ok, makes sense, let's split that into a separate PR? |
For the hastebin I linked above or the route resolver into class thing? While the hastebin I linked is sizeable, including it means that this PR doesn't change functionality when it comes to If you mean route resolvers into classes, then yeah I absolutely agree |
The hastebin code might take more work, so I think it's better to have a new PR to keep the diff smaller. If possible maybe we can avoid importing |
You bring up a very good point about minimizing bundle size. In that case, we might want to escalate #2275 for this release, so that we can define a custom route resolver for DiscussionPage that would contain this custom logic. If we want to have more internal discussion, we might want to avoid exporting the route resolver classes in compat until beta 15. |
🤔 Not sure what I'm supposed to test with this PR, but nothing seems broken. However, the behavior of links in e.g. profile page vs index page isn't the same - index page sidebar links do not "force" the route (or whatever the terminology we're using is) unlike the home button or the profile page sidebar. Apart from that, looks like stuff works 🤷 |
Iirc, that particular piece (setting Link Buttons to force by default) wasn't included here to minimize the diff and avoid unnecessary changes. Goal here is to change the rerendering system, that can be taken care of separately. |
Hm I was just mentioning it because those are the only buttons that don't have that behavior now - the sidebar in user page does. Ok, I'll approve. |
Fixes #2376, Fixes #2368
Edit: Using a
view
component instead of therender
route resolver, allows for page components to unload properly instead of diffing.Using the
Link
component with thekey
state
(force
) attribute would allow for same route name components to unload again like in beta.13. So it would be possible to useoninit
andoncreate
for those without workarounds.Edit2: New approach uses now again route resolvers, and removes the need for
setRouteWithForcedRefresh
and theLink
force
attribute.Confirmed