I had no success to the Vue component "SSR-ed" in the page source.
AI summary for this issue:
Title: Fix SSR markup handoff and Vue hydration for SDX components
Problem/Motivation
Vue components rendered through SDX do not consistently produce usable server-rendered markup in Drupal.
The SSR pre-render callback adds the rendered HTML to the component render array's #props, but Drupal's inline component template renders from inline-template.#context. As a result, the SSR HTML may not reach the Twig output, and the page source contains the component wrapper and props JSON without the component's rendered markup.
When the SSR HTML is passed through to the Vue mount container, its props JSON script is also a child of that container. Vue hydration can treat that script as part of the server-rendered component tree, causing incorrect hydration or duplicate component output.
Steps to reproduce
- Enable SDX for Vue and enable the SDX SSR feature.
- Build the Vue component and its SSR bundle, and ensure the SSR service is available.
- Render an SSR-enabled Vue component in a Drupal template using SDX.
- Inspect the page source. The component wrapper and props JSON are present, but the expected server-rendered component markup is missing.
- After passing the SSR markup into the Vue mount container, observe hydration. The props JSON script can interfere with hydration and the component may be rendered twice.
Proposed resolution
- Make the SSR pre-render callback add the rendered HTML to the inline template context consumed by the SDX Twig template, as well as retaining it in the component props.
- Update the Vue hydration adapter to exclude the SDX props JSON script while Vue hydrates the server-rendered component, then restore the script after hydration.
- Add regression tests for SSR HTML propagation into the inline template context and for Vue hydration with the props JSON script present.
- Keep the existing client-side rendering fallback when SSR is unavailable or fails.
Remaining tasks
- Confirm the SSR handoff fix works with SDX's Twig component rendering.
- Verify Vue hydrates the server-rendered output without duplicate component markup.
- Run the relevant SDX SSR and Vue tests.
User interface changes
No intended visual changes. With SSR enabled, the component's rendered markup should be present in the initial HTML and remain correctly hydrated by Vue.
API changes
None expected.
Data model changes
None.
Issue fork sdx-3632648
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
vasikeThere is MR done by AI ... that put the SSR html in place for the Vue components
But maybe there is and should be a better way ...
Comment #6
vzsigmond commentedHi @vasike
Thanks for reporting this and putting together the MR. I've opened MR !4, which builds on your findings by fixing the render order and moving the props JSON outside the hydration container.
SSR and interactive hydration work in React, Vue and Svelte. There's also a separate issue with the Svelte test runner that I'll address before merging.
Comment #7
vasikeI did a checkout on your MR branch and rebuilt ... and it seems the SSR for Vue components still works/there.
Do you need any specific feedback from me, about your MR - something to check/test?
p.s. maybe a
.gitlab-ci.ymlsetup would help with the MRs here.Comment #9
vzsigmond commentedThat confirmation is what I needed :-) The fix is now merged into 1.0.x, and the Svelte test runner issue is resolved too.
Agreed about GitLab CI, that would be a useful follow-up. Thanks for the report, the original MR and helping verify the fix. Marking this fixed.