better code
Massimo Melina committed
Oct 22, 2025 at 23:08 UTC
c65d2df1fb5cc37c7852fd10c16b3e2944a0ec43
2 files changed
+7
-8
frontend/src/components.ts
+3
-5
@@ -89,19 +89,17 @@ export function CustomCode({ name, children, render, ...props }: {
89
if (raw.isDefaultPrevented() || raw.some(x => x === null)) // null means skip this
90
return setOut(null)
91
const worked: ReactNode[] = raw.map(toElement)
92
- setOut(onlyTruthy(worked))
92
raw.forEach((x, i) => {
94
- if (typeof x?.then === 'function') // thenable
93
+ if (typeof x?.then === 'function') // then-able
94
x.then((resolved: any) => {
95
worked[i] = toElement(resolved, i)
96
setOut(onlyTruthy(worked))
97
}, () => {})
98
})
99
const html = getHFS().customHtml?.[name]
101
- if (html?.trim?.()) {
100
+ if (html?.trim?.())
101
worked.push(toElement(html, -1))
103
- setOut(onlyTruthy(worked))
104
- }
102
+ setOut(onlyTruthy(worked))
103
104
function toElement(x: unknown, key: number) {
105
return isValidElement(x) ? h(Fragment, { key }, x) // wrap to avoid console warnings
src/plugins.ts
+4
-3
@@ -268,12 +268,13 @@ export class Plugin implements CommonPluginInterface {
268
269
const keys = Array.from(plugins.keys())
270
const idx = keys.indexOf(id)
271
+ // initialize moveDown with existing plugins that want to be after this
272
const moveDown = onlyTruthy(mapPlugins(((pl, plId, plIdx) => pl.afterPlugin === id && plIdx < idx && plId)))
272
- const {beforePlugin, afterPlugin} = data // or this plugin that wants to be considered before another
273
+ const {beforePlugin, afterPlugin} = data // then consider what this plugin wants
274
if (afterPlugin && keys.indexOf(afterPlugin) > idx)
274
- moveDown.push(id)
275
+ moveDown.push(id) // move down this plugin
276
if (beforePlugin && keys.indexOf(beforePlugin) < idx)
276
- moveDown.push(beforePlugin)
277
+ moveDown.push(beforePlugin) // move down the other plugin
278
for (const k of moveDown) {
279
const temp = plugins.get(k)
280
if (!temp) continue