From f2a5751f3eaca3ed6c41716f6b2131508c43819e Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Thu, 17 Aug 2023 20:03:09 +0200 Subject: [PATCH] Revert 173 revert 155 fix/useconfirm n tableofcont (#177) * test * test * test * test * errorWhileRendering now generates 500 status code * build fix * debug cleanup --- api/ssr.js | 9 ++++++- src/components/Article/FullArticle.tsx | 2 +- src/components/Editor/Editor.tsx | 2 +- .../TableOfContents/TableOfContents.tsx | 26 ++++++++++++++----- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/api/ssr.js b/api/ssr.js index 567e5a2f..4a9d60d0 100644 --- a/api/ssr.js +++ b/api/ssr.js @@ -5,7 +5,14 @@ export default async function handler(req, res) { const pageContext = await renderPage({ urlOriginal: url, cookies }) - const { httpResponse } = pageContext + const { httpResponse, errorWhileRendering } = pageContext + + if (errorWhileRendering) { + console.error(errorWhileRendering) + res.statusCode = 500 + res.end() + return + } if (!httpResponse) { res.statusCode = 200 diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 9cd0f253..2d9e8499 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -232,7 +232,7 @@ export const FullArticle = (props: Props) => { - + diff --git a/src/components/Editor/Editor.tsx b/src/components/Editor/Editor.tsx index adddf04b..64cc75b5 100644 --- a/src/components/Editor/Editor.tsx +++ b/src/components/Editor/Editor.tsx @@ -248,7 +248,7 @@ export const Editor = (props: Props) => { <>
(editorElRef.current = el)} id="editorBody" /> - + { @@ -32,21 +33,34 @@ export const TableOfContents = (props: Props) => { const [headings, setHeadings] = createSignal([]) const [areHeadingsLoaded, setAreHeadingsLoaded] = createSignal(false) - const [isVisible, setIsVisible] = createSignal(true) + const [isVisible, setIsVisible] = createSignal(props.variant === 'article') const toggleIsVisible = () => { setIsVisible((visible) => !visible) } - onMount(() => { + const updateHeadings = () => { const { parentSelector } = props + // eslint-disable-next-line unicorn/prefer-spread setHeadings(Array.from(document.querySelector(parentSelector).querySelectorAll('h2, h3, h4'))) - setAreHeadingsLoaded(true) - }) + } + + const debouncedUpdateHeadings = debounce(updateHeadings, 500) + + createEffect( + on( + () => props.body, + () => debouncedUpdateHeadings() + ) + ) return ( - + 2 : headings().length > 1) + } + >