Repository navigation
Rendering WebComponents server-side at SSG time #1290
Replies: 2 comments 1 reply
|
Based on the current implementation, I would not treat the Pagefind components as SSR-hydratable yet. All of them inherit from pagefind/pagefind_ui/component/components/base-element.ts Lines 20 to 28 in 7776ce6 For pagefind/pagefind_ui/component/components/pagefind-searchbox.ts Lines 308 to 351 in 7776ce6 It preserves the Pagefind template That makes the current components fall into roughly three groups:
For an instantly visible search field, I would use progressive enhancement instead:
The native field can be CSS-only before enhancement, but actual Pagefind search and keyboard behavior still require JavaScript. Also, the standalone https://pagefind.app/docs/components/input/#behavior So if the main goal is to avoid loading the search engine before interaction, using the input component with deferred component JavaScript may already provide most of the benefit. SSR of the Pagefind-generated internals would need an explicit hydration/adopt-existing-DOM path in the components to avoid the replacement described above. |
|
@vadimkantorov Thanks, and you are right to distinguish this as SSG rather than SSR. With Astro plus LinkeDOM and a customElements shim, you can generate the static first-paint HTML you describe. The caveat I meant is the client handoff: when the Pagefind component bundle is eventually registered, the current render path replaces the existing light DOM rather than hydrating it. That is still a workable progressive-enhancement model:
That keeps the control visible without the search runtime and only pays for Pagefind when the user shows intent. pagefind-input and pagefind-searchbox are the most useful candidates; results and filters need runtime query state anyway. A native fallback is also less coupled to the internal component markup. For dialog, the open attribute can display a dialog without JavaScript, but it is not a modal dialog in the full platform sense. Opening it from an interaction with showModal(), entering the top layer, backdrop behavior, and focus management still need JavaScript. So static search UI is realistic, while a click-to-open accessible modal needs the small activation loader. An explicit adopt-existing-DOM mode would make this smoother, but SSG output plus deferred replacement already seems viable today. |
Uh oh!
There was an error while loading. Please reload this page.
Hi! I'm considering rendering some of Pagefind components serverside during SSG (using approach from https://dev.to/thepassle/server-side-rendering-vanilla-custom-elements-in-astro-5hgg) in order to pre-render and make instantly rendered the main HTML elements, and delay reliance on JavaScript to user actually interacting with the search box.
Which of the Pagefind web-components should be amenable to this approach?
I imagine that the search box web component should be renderable server-side, right? (and unless interacted with, it should require just CSS, right?)
All reactions