From 304f7757d9181496d5aed2045a9ab3a9f0814569 Mon Sep 17 00:00:00 2001 From: Matthias Camenzind Date: Thu, 11 Apr 2024 10:35:15 +0200 Subject: [PATCH 1/5] Enable @babel/plugin-proposal-decorators Dependency already exists --- .babelrc | 7 ++++++- tsconfig.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.babelrc b/.babelrc index fbfb0025d..0b2c69397 100644 --- a/.babelrc +++ b/.babelrc @@ -13,7 +13,12 @@ ["@babel/typescript", { "isTSX": true, "allExtensions": true }] ], "plugins": [ - "@babel/plugin-transform-runtime", + ["@babel/plugin-proposal-decorators", { "version": "legacy" }], + [ + "@babel/plugin-transform-runtime", + // version defaults to 7.0.0 for which non-legacy decorators produce duplicate code + { "version": "^7.24.3" } + ], ["babel-plugin-inferno", { "imports": true }], ["@babel/plugin-transform-class-properties", { "loose": true }] ] diff --git a/tsconfig.json b/tsconfig.json index aa4f70de9..ed5755289 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,7 @@ "skipLibCheck": true, "noUnusedParameters": true, "noImplicitReturns": true, - "experimentalDecorators": true, + "experimentalDecorators": true, // false for non-legacy decorators "strictNullChecks": true, "noFallthroughCasesInSwitch": true, "paths": { From abf725af29ce16bdff3abcb64ca71da991b0213b Mon Sep 17 00:00:00 2001 From: Matthias Camenzind Date: Thu, 11 Apr 2024 10:35:18 +0200 Subject: [PATCH 2/5] Use tippy.js delegate addon, cleanup tippy instances from a mixin. The delegate addon creates tippy instances from mouse and touch events with a matching `event.target`. This is initially significantly cheaper than creating all instances at once. The addon keeps all created tippy instances alive until it is destroyed itself. `tippyMixin` destroys the addon instance after every render, as long as all instances are hidden. This drops some tippy instances that may have to be recreated later (e.g when the mouse moves over the trigger again), but is otherwise fairly cheap (creates one tippy instance). --- .eslintrc.json | 4 ++ src/shared/components/app/app.tsx | 12 +++- src/shared/components/app/navbar.tsx | 2 + .../components/comment/comment-node.tsx | 5 +- .../components/comment/comment-report.tsx | 2 + .../common/content-actions/action-button.tsx | 2 + .../content-action-dropdown.tsx | 2 + src/shared/components/common/emoji-picker.tsx | 2 + .../components/common/markdown-textarea.tsx | 12 ++-- src/shared/components/common/moment-time.tsx | 2 + .../components/common/password-input.tsx | 2 + src/shared/components/common/user-badges.tsx | 4 +- src/shared/components/common/vote-buttons.tsx | 13 +++- .../components/community/community-form.tsx | 2 + src/shared/components/community/community.tsx | 7 +-- src/shared/components/community/sidebar.tsx | 2 + src/shared/components/home/emojis-form.tsx | 2 + src/shared/components/home/home.tsx | 7 +-- src/shared/components/home/site-sidebar.tsx | 2 + src/shared/components/home/tagline-form.tsx | 2 + src/shared/components/mixins/tippy-mixin.ts | 25 ++++++++ src/shared/components/person/cake-day.tsx | 2 + .../components/person/person-details.tsx | 5 -- src/shared/components/person/profile.tsx | 2 - .../person/registration-applications.tsx | 2 - src/shared/components/person/settings.tsx | 4 +- src/shared/components/post/post-form.tsx | 2 - src/shared/components/post/post-listing.tsx | 5 +- src/shared/components/post/post-report.tsx | 2 + src/shared/components/post/post.tsx | 3 - .../private_message/private-message-form.tsx | 5 -- .../private-message-report.tsx | 2 + .../private_message/private-message.tsx | 2 + src/shared/tippy.ts | 62 +++++++++++++++---- 34 files changed, 150 insertions(+), 61 deletions(-) create mode 100644 src/shared/components/mixins/tippy-mixin.ts diff --git a/.eslintrc.json b/.eslintrc.json index 4d0e75628..651ba006b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,10 @@ "@typescript-eslint/explicit-module-boundary-types": 0, "@typescript-eslint/no-empty-function": 0, "@typescript-eslint/no-non-null-assertion": 0, + "@typescript-eslint/no-unused-vars": [ + "error", + { "argsIgnorePattern": "^_" } + ], "arrow-body-style": 0, "curly": 0, "eol-last": 0, diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index 30f445f7f..1538b0450 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -13,15 +13,25 @@ import { Navbar } from "./navbar"; import "./styles.scss"; import { Theme } from "./theme"; import AnonymousGuard from "../common/anonymous-guard"; +import { destroyTippy, setupTippy } from "../../tippy"; export class App extends Component { private isoData: IsoDataOptionalSite = setIsoData(this.context); private readonly mainContentRef: RefObject; + private readonly rootRef = createRef(); constructor(props: any, context: any) { super(props, context); this.mainContentRef = createRef(); } + componentDidMount(): void { + setupTippy(this.rootRef); + } + + componentWillUnmount(): void { + destroyTippy(); + } + handleJumpToContent(event) { event.preventDefault(); this.mainContentRef.current?.focus(); @@ -34,7 +44,7 @@ export class App extends Component { return ( <> -
+