From d49c855a15fd2ec574050b33294bfe8847d0be8a Mon Sep 17 00:00:00 2001
From: Lim Chee Aun
Date: Sun, 8 Sep 2024 18:08:02 +0800
Subject: [PATCH] Add hidden debugging info
---
src/app.css | 22 ++++++++++++++++++++++
src/app.jsx | 23 +++++++++++++++++++++++
src/locales/en.po | 38 +++++++++++++++++++-------------------
src/pages/settings.jsx | 17 +++++++++++++++++
4 files changed, 81 insertions(+), 19 deletions(-)
diff --git a/src/app.css b/src/app.css
index a773b8ee..afd2d0fa 100644
--- a/src/app.css
+++ b/src/app.css
@@ -2907,3 +2907,25 @@ ul.link-list li a .icon {
width: 10em;
}
}
+
+/* DEBUG */
+
+.debug-info {
+ font-size: smaller;
+ summary {
+ height: 1em;
+ width: 100%;
+ list-style: none;
+ display: inline-block;
+ }
+ summary::-webkit-details-marker {
+ display: none;
+ }
+
+ p,
+ ol,
+ ul {
+ margin-block-start: 0;
+ padding-block-start: 0;
+ }
+}
diff --git a/src/app.jsx b/src/app.jsx
index 4db0a8cb..9c425fa0 100644
--- a/src/app.jsx
+++ b/src/app.jsx
@@ -301,9 +301,30 @@ subscribe(states, (changes) => {
}
});
+const BENCHES = new Map();
+window.__BENCH_RESULTS = new Map();
+window.__BENCHMARK = {
+ start(name) {
+ if (!import.meta.env.DEV) return;
+ const start = performance.now();
+ BENCHES.set(name, start);
+ },
+ end(name) {
+ if (!import.meta.env.DEV) return;
+ const start = BENCHES.get(name);
+ if (start) {
+ const end = performance.now();
+ const duration = end - start;
+ __BENCH_RESULTS.set(name, duration);
+ BENCHES.delete(name);
+ }
+ },
+};
+
function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [uiState, setUIState] = useState('loading');
+ __BENCHMARK.start('app-init');
useLingui();
useEffect(() => {
@@ -351,6 +372,7 @@ function App() {
} else {
setUIState('error');
}
+ __BENCHMARK.end('app-init');
})();
} else {
window.__IGNORE_GET_ACCOUNT_ERROR__ = true;
@@ -393,6 +415,7 @@ function App() {
} else {
setUIState('default');
}
+ __BENCHMARK.end('app-init');
}
// Cleanup
diff --git a/src/locales/en.po b/src/locales/en.po
index 088c2d75..fbdb50cb 100644
--- a/src/locales/en.po
+++ b/src/locales/en.po
@@ -194,7 +194,7 @@ msgstr ""
#: src/pages/catchup.jsx:72
#: src/pages/catchup.jsx:1430
#: src/pages/catchup.jsx:2051
-#: src/pages/settings.jsx:1028
+#: src/pages/settings.jsx:1045
msgid "Boosts"
msgstr ""
@@ -1251,7 +1251,7 @@ msgstr ""
#: src/pages/home.jsx:223
#: src/pages/mentions.jsx:20
#: src/pages/mentions.jsx:167
-#: src/pages/settings.jsx:1020
+#: src/pages/settings.jsx:1037
#: src/pages/trending.jsx:347
msgid "Mentions"
msgstr ""
@@ -1306,7 +1306,7 @@ msgstr ""
#: src/pages/catchup.jsx:2045
#: src/pages/favourites.jsx:11
#: src/pages/favourites.jsx:23
-#: src/pages/settings.jsx:1024
+#: src/pages/settings.jsx:1041
msgid "Likes"
msgstr ""
@@ -2292,7 +2292,7 @@ msgid "<0/> <1/> boosted"
msgstr ""
#: src/components/timeline.jsx:451
-#: src/pages/settings.jsx:1048
+#: src/pages/settings.jsx:1065
msgid "New posts"
msgstr ""
@@ -3131,7 +3131,7 @@ msgid "{0, plural, one {Announcement} other {Announcements}}"
msgstr ""
#: src/pages/notifications.jsx:599
-#: src/pages/settings.jsx:1036
+#: src/pages/settings.jsx:1053
msgid "Follow requests"
msgstr ""
@@ -3486,56 +3486,56 @@ msgstr ""
msgid "Unable to copy version string"
msgstr ""
-#: src/pages/settings.jsx:933
-#: src/pages/settings.jsx:938
+#: src/pages/settings.jsx:950
+#: src/pages/settings.jsx:955
msgid "Failed to update subscription. Please try again."
msgstr ""
-#: src/pages/settings.jsx:944
+#: src/pages/settings.jsx:961
msgid "Failed to remove subscription. Please try again."
msgstr ""
-#: src/pages/settings.jsx:951
+#: src/pages/settings.jsx:968
msgid "Push Notifications (beta)"
msgstr ""
-#: src/pages/settings.jsx:973
+#: src/pages/settings.jsx:990
msgid "Push notifications are blocked. Please enable them in your browser settings."
msgstr ""
-#: src/pages/settings.jsx:982
+#: src/pages/settings.jsx:999
msgid "Allow from <0>{0}0>"
msgstr ""
-#: src/pages/settings.jsx:991
+#: src/pages/settings.jsx:1008
msgid "anyone"
msgstr ""
-#: src/pages/settings.jsx:995
+#: src/pages/settings.jsx:1012
msgid "people I follow"
msgstr ""
-#: src/pages/settings.jsx:999
+#: src/pages/settings.jsx:1016
msgid "followers"
msgstr ""
-#: src/pages/settings.jsx:1032
+#: src/pages/settings.jsx:1049
msgid "Follows"
msgstr ""
-#: src/pages/settings.jsx:1040
+#: src/pages/settings.jsx:1057
msgid "Polls"
msgstr ""
-#: src/pages/settings.jsx:1044
+#: src/pages/settings.jsx:1061
msgid "Post edits"
msgstr ""
-#: src/pages/settings.jsx:1065
+#: src/pages/settings.jsx:1082
msgid "Push permission was not granted since your last login. You'll need to <0><1>log in1> again to grant push permission0>."
msgstr ""
-#: src/pages/settings.jsx:1081
+#: src/pages/settings.jsx:1098
msgid "NOTE: Push notifications only work for <0>one account0>."
msgstr ""
diff --git a/src/pages/settings.jsx b/src/pages/settings.jsx
index 43587e93..961cd5fa 100644
--- a/src/pages/settings.jsx
+++ b/src/pages/settings.jsx
@@ -826,6 +826,23 @@ function Settings({ onClose }) {
)}
+ {import.meta.env.DEV && (
+
+
+ Debugging
+ {__BENCH_RESULTS?.size > 0 && (
+
+ {Array.from(__BENCH_RESULTS.entries()).map(
+ ([name, duration]) => (
+ -
+ {name}: {duration}ms
+
+ ),
+ )}
+
+ )}
+
+ )}
);