From e2bceeea0e0ee654b5d0bba709cbac830e5b44e7 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Mon, 6 Apr 2026 18:35:15 +0530 Subject: [PATCH 1/2] fix: eliminate layout shifts on public wiki page load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three root causes of CLS (Cumulative Layout Shift) on the Jinja-rendered wiki pages: 1. Sidebar width was entirely set by Alpine's :style binding — before Alpine loaded, the sidebar had no width, causing content to reflow. Fixed by adding w-72 as default CSS width and a blocking script that reads the persisted collapse state from localStorage (same pattern as the existing theme initialization). 2. Sidebar tree children were all visible in raw HTML, then collapsed by Alpine, then re-expanded for ancestors — two sequential shifts. Fixed by computing ancestor nodes server-side and passing them to the template, which uses x-cloak on non-ancestor children so they start hidden. 3. Content area had transition-[max-width] with max-w-[80ch]. The ch unit depends on font glyph width — when InterVar loaded via font-display:swap, the ch value changed and the transition animated the content width over 300ms. Fixed by transitioning only opacity. 4. Search shortcut kbd was empty until Alpine's x-text filled it in. Fixed by adding default text content. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../doctype/wiki_document/wiki_document.py | 4 ++++ wiki/templates/wiki/document.html | 2 +- wiki/templates/wiki/includes/header.html | 2 +- wiki/templates/wiki/includes/sidebar.html | 10 +++++++--- wiki/templates/wiki/layout.html | 18 ++++++++++++++++-- wiki/templates/wiki/macros/sidebar_tree.html | 7 ++++--- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/wiki/frappe_wiki/doctype/wiki_document/wiki_document.py b/wiki/frappe_wiki/doctype/wiki_document/wiki_document.py index 5d5162d4..0fcd231a 100644 --- a/wiki/frappe_wiki/doctype/wiki_document/wiki_document.py +++ b/wiki/frappe_wiki/doctype/wiki_document/wiki_document.py @@ -322,6 +322,9 @@ def get_web_context(self) -> dict: # Render markdown and extract TOC headings in one pass rendered_content, toc_headings = render_markdown_with_toc(self.content or "") + # Ancestor nodes that should be expanded in the sidebar tree on initial render + expanded_nodes = set(self.get_ancestors()) if self.lft else set() + # Base context with defaults for orphan documents context = { "doc": self, @@ -335,6 +338,7 @@ def get_web_context(self) -> dict: "toc_headings": toc_headings, "raw_markdown": self.content or "", "nested_tree": [], + "expanded_nodes": expanded_nodes, "prev_doc": None, "next_doc": None, "edit_link": self.get_edit_link(), diff --git a/wiki/templates/wiki/document.html b/wiki/templates/wiki/document.html index 8ead2fff..cc43ce4d 100644 --- a/wiki/templates/wiki/document.html +++ b/wiki/templates/wiki/document.html @@ -13,7 +13,7 @@
-
diff --git a/wiki/templates/wiki/includes/header.html b/wiki/templates/wiki/includes/header.html index 74e448f6..01c6735d 100644 --- a/wiki/templates/wiki/includes/header.html +++ b/wiki/templates/wiki/includes/header.html @@ -61,7 +61,7 @@ {# Separator before toggle (only if there are text links) #} diff --git a/wiki/templates/wiki/includes/sidebar.html b/wiki/templates/wiki/includes/sidebar.html index 5850c55f..d58edf88 100644 --- a/wiki/templates/wiki/includes/sidebar.html +++ b/wiki/templates/wiki/includes/sidebar.html @@ -1,19 +1,19 @@ {% from "templates/wiki/macros/sidebar_tree.html" import render_wiki_tree %} {% from "templates/wiki/macros/buttons.html" import ghost_button_full, icon_button, render_icon %} -