Skip to content

fix: enable SSR support for Vaul without using Portal#598

Open
m-anikanov wants to merge 1 commit intoemilkowalski:mainfrom
m-anikanov:main
Open

fix: enable SSR support for Vaul without using Portal#598
m-anikanov wants to merge 1 commit intoemilkowalski:mainfrom
m-anikanov:main

Conversation

@m-anikanov
Copy link
Copy Markdown

When attempting to use Vaul in SSR (Server-Side Rendering) mode without Portal, the application throws an error due to direct access to the document object, which is not available in a server environment.

This commit addresses that issue by ensuring that document is defined. This allows Vaul to render content directly into the DOM during SSR, which is critical for SEO purposes.

This fix makes it possible to safely render Vaul modals server-side without relying on a Portal, improving compatibility with SSR frameworks (like Next.js) and better supporting SEO-sensitive use cases.

When attempting to use Vaul in SSR (Server-Side Rendering) mode without Portal, the application throws an error due to direct access to the document object, which is not available in a server environment.

This commit addresses that issue by ensuring that any DOM-specific logic (such as referencing document.body or manipulating the DOM) is gated behind a client-only check. This allows Vaul to render content directly into the DOM during SSR, which is critical for SEO purposes—ensuring that the initial HTML contains the modal content for proper indexing by search engines.

This fix makes it possible to safely render Vaul modals server-side without relying on a Portal, improving compatibility with SSR frameworks and better supporting SEO-sensitive use cases.
@gstcarv
Copy link
Copy Markdown

gstcarv commented Sep 8, 2025

any chance of merging this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants