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

Mithril 2 update #2255

Merged
merged 6 commits into from
Sep 24, 2020
Merged

Mithril 2 update #2255

merged 6 commits into from
Sep 24, 2020

Conversation

dsevillamartin
Copy link
Member

@dsevillamartin dsevillamartin commented Aug 5, 2020

Supersedes #2126.

Some minor TypeScript changes will be here because it makes the development easier. Don't yell at us.

Decisions made thus far:

  • mithril 2.0 does not rerun oninit hooks for page components when a change in route results in the same page. There is general agreement that we want to keep / allow the old behavior. The current implementation is a well documented patch in patchMithril.js, but we are happy to consider alternatives.
  • Children is no longer passed to AlertManagerState through attrs; it is now the first argument (attrs is second, componentClass isthird). We might want to switch the order to have attrs before children, but I feel like children is more likely to be provided.
  • onunload methods have been merged with context.onunload (from config) into onremove. I am not sure if this is the right way to do this, but it seems to make sense and hasn't broken anything so far
  • Instead of returning a retain vnode, subtree retainer now returns a boolean value, which can be used in onbeforeupdate.
  • in many cases, we pass a "config" attr to some html element instead of creating a custom component for it. Since there are now multiple life cycle hooks, not just config, passing multiple of those would be inconvenient. If multiple hooks, or logic more than a few lines, needs to be passed as attrs to a component, I am creating a new component for it (e.g. CommentPostPreview, ReplyPlaceholderPreview)
  • despite the consensus in the previous team meeting to not store this.attrs, on implementation, that has turned out more difficult than expected, as we'd need to pass attrs through long chains of sometimes more than 5 methods. We have reverted to using this.attrs, and are also keeping initAttrs (although thst is NOT static anymore)
  • we are no longer using attrs.children to pass in children. We've even added a warning error message to deter against this.
  • In some cases, attrs would be passed to an html vnode, which are distinct from the attrs passed to the component. Previously, these were managed via an attrs method. However, since we now use this.attrs, that will not work. We are renaming those methods to elementAttrs.
  • mapRoutes no longer sets a routeName attr on components
  • All frontend deprecated code has been removed, except for various warnings/errors designed to prevent wrong inputs.

References to props in comments have not been changed; they will be removed when we introduce attr typing in the typescript part of the rewrite.

Some issues that need fixes

  • e0fce1c is messy... Do we want to abstractify these components, and bring them out of this file?

Extracted fixes:

@askvortsov1
Copy link
Member

askvortsov1 commented Aug 10, 2020

Decisions made thus far:

  • mithril 2.0 does not rerun oninit hooks for page components when a change in route results in the same page. There is general agreement that we want to keep / allow the old behavior. The current implementation is a well documented patch in patchMithril.js, but we are happy to consider alternatives.
  • Children is no longer passed to AlertManagerState through attrs; it is now the first argument (attrs is second, componentClass isthird). We might want to switch the order to have attrs before children, but I feel like children is more likely to be provided.
  • onunload methods have been merged with context.onunload (from config) into onremove. I am not sure if this is the right way to do this, but it seems to make sense and hasn't broken anything so far
  • Instead of returning a retain vnode, subtree retainer now returns a boolean value, which can be used in onbeforeupdate.
  • in many cases, we pass a "config" attr to some html element instead of creating a custom component for it. Since there are now multiple life cycle hooks, not just config, passing multiple of those would be inconvenient. If multiple hooks, or logic more than a few lines, needs to be passed as attrs to a component, I am creating a new component for it (e.g. CommentPostPreview, ReplyPlaceholderPreview)
  • despite the consensus in the previous team meeting to not store this.attrs, on implementation, that has turned out more difficult than expected, as we'd need to pass attrs through long chains of sometimes more than 5 methods. We have reverted to using this.attrs, and are also keeping initAttrs (although thst is NOT static anymore)
  • we are no longer using attrs.children to pass in children. We've even added a warning error message to deter against this.
  • In some cases, attrs would be passed to an html vnode, which are distinct from the attrs passed to the component. Previously, these were managed via an attrs method. However, since we now use this.attrs, that will not work. We are renaming those methods to elementAttrs.
  • affixSidebar util has been removed in favor of an AffixedSidebar component
  • mapRoutes no longer sets a routeName attr on components
  • All frontend deprecated code has been removed, except for various warnings/errors designed to prevent wrong inputs.

References to props in comments have not been changed; they will be removed when we introduce attr typing in the typescript part of the rewrite.

Some issues that need fixes

  • Notifications linking to external sites might not link to them properly. Can we use external URLs with m.route.link?
  • e0fce1c is messy... Do we want to abstractify these components, and bring them out of this file?

@askvortsov1 askvortsov1 force-pushed the mithril-2-update branch 3 times, most recently from a1c8ae1 to 356215e Compare August 11, 2020 00:27
Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

Found a bunch of stuff already. Haven't looked at all files yet, though.

js/src/admin/components/UploadImageButton.js Outdated Show resolved Hide resolved
js/src/admin/components/SettingDropdown.js Outdated Show resolved Hide resolved
js/src/admin/components/SessionDropdown.js Outdated Show resolved Hide resolved
js/src/admin/components/AdminLinkButton.js Outdated Show resolved Hide resolved
js/src/common/components/Alert.js Outdated Show resolved Hide resolved
js/src/forum/components/SignUpModal.js Show resolved Hide resolved
js/src/forum/components/SignUpModal.js Outdated Show resolved Hide resolved
js/src/common/utils/withAttr.ts Show resolved Hide resolved
js/src/common/utils/extractText.js Show resolved Hide resolved
js/src/common/utils/SubtreeRetainer.js Show resolved Hide resolved
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

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

I'd like to suggest we create a util method or Mithril patch for m.route.set('/', null, { state: { key: Date.now() } });. It's not obvious what it does and it would be much simpler to have it inside of a named method instead of adding a comment everywhere. Something like setRouteWithForcedRefresh()

I have read through the changes in this PR last week and again now and I think it's still not an exhaustive review but I think I agree with the vast majority of changes.

js/src/forum/components/UserPage.js Outdated Show resolved Hide resolved
js/src/forum/components/AffixedSidebar.js Show resolved Hide resolved
js/src/forum/components/TextEditor.js Outdated Show resolved Hide resolved
@askvortsov1
Copy link
Member

I'd like to suggest we create a util method or Mithril patch for m.route.set('/', null, { state: { key: Date.now() } });. It's not obvious what it does and it would be much simpler to have it inside of a named method instead of adding a comment everywhere. Something like setRouteWithForcedRefresh()

That's a great idea! Also allows us to document this centrally. Done!

Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

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

All good regarding my previous comments. Not sure if I should do another read-through before the end of the week or if it's enough to wait on others to complete their own review?

Copy link
Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

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

Ooo 2 approving reviews, does that mean we can merge 🤣
(just to clarify, no merge until everyone agrees or Franz overrides. This approval is largely symbolic in that I think thisr implementation is sufficient to not diminish extensibility, and does not introduce bugs (that I have been able to find))

Copy link
Member Author

@dsevillamartin dsevillamartin left a comment

Choose a reason for hiding this comment

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

js/src/forum/components/CommentPost.js Outdated Show resolved Hide resolved
js/src/forum/components/CommentPost.js Show resolved Hide resolved
js/src/forum/components/PostEdited.js Show resolved Hide resolved
js/src/forum/components/DiscussionListItem.js Show resolved Hide resolved
js/src/common/components/LinkButton.js Show resolved Hide resolved
Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

A few post stream questions for @askvortsov1

js/src/forum/components/PostStreamScrubber.js Outdated Show resolved Hide resolved
js/src/forum/components/PostStream.js Outdated Show resolved Hide resolved
js/src/forum/components/PostStream.js Outdated Show resolved Hide resolved
js/src/forum/components/PostStreamScrubber.js Show resolved Hide resolved
- Update libraries
- Add Typescript typings for Mithril
- Rename "props" to "attrs"
- New lifecycle hooks
- Other mechanical changes, following the upgrade guide
- Remove some of the custom stuff in our Component base class
- Introduce "fragments" for non-components that control their own DOM
- Remove Mithril patches, introduce a few new ones

Challenges:
- Behavior of links to current page changed in Mithril
- Native Promise rejections are shown on console when not handled
- ...

Refs #1821.

Co-authored-by: Alexander Skvortsov <sasha.skvortsov109@gmail.com>
Co-authored-by: Matthew Kilgore <tankerkiller125@gmail.com>
Co-authored-by: Franz Liedke <franz@develophp.org>
@franzliedke
Copy link
Contributor

Congrats! 🎉

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

Successfully merging this pull request may close these issues.

5 participants