Skip to content

test: cover the SSR and "use client" guarantees - #57

Open
sidgaikwad wants to merge 1 commit into
unlayer:mainfrom
sidgaikwad:test/ssr-smoke
Open

test: cover the SSR and "use client" guarantees#57
sidgaikwad wants to merge 1 commit into
unlayer:mainfrom
sidgaikwad:test/ssr-smoke

Conversation

@sidgaikwad

Copy link
Copy Markdown
Contributor

Fixes #41.

The README makes two promises that nothing verified:

works out of the box in React Server Components environments (e.g. Next.js App Router) — it ships with the 'use client' directive and touches the DOM only inside effects

The whole suite runs in jsdom, so every test renders client-side, and the 'use client' banner is a tsup config detail — a bundler or config change could drop it and every existing test would still pass.

New test/ssr.test.tsx, running with @vitest-environment node

  1. Asserts there is genuinely no DOM in that environment first — otherwise, if jsdom leaked in, the rest of the file would prove nothing.
  2. renderToString the component, bare and again with every prop set. Effects don't run on the server, so a prop that reached the DOM during render rather than in an effect would throw here.
  3. Asserts both built bundles start with 'use client';.

Verification

The banner assertion is not decorative — I deleted the banner line from tsup.config.ts, rebuilt, and it failed:

× ships the "use client" directive in both builds

It also skips cleanly rather than failing when dist/ is absent:

Tests  3 passed | 1 skipped (4)

That matters because the checks CI job runs npm run build before the tests (so it executes there), while the Node/React matrix jobs run npm test without building (so it skips).

  • 4 new tests; 50 total; coverage still 100% across the board
  • lint, typecheck clean

The README states the component works in React Server Components
environments, and that it touches the DOM only inside effects. Nothing
verified either claim: the whole suite runs in jsdom, and the 'use client'
banner is a tsup config detail that a bundler or config change could
silently drop with every existing test still passing.

Add test/ssr.test.tsx, which runs with `@vitest-environment node`:

- asserts there really is no DOM in that environment, so the rest of the
  file proves something
- renders the component with renderToString, bare and with every prop set
- asserts both built bundles start with 'use client'

The dist assertion is skipped when dist/ is absent, so it runs in the CI
job that builds first and does not fail the Node/React matrix jobs.
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

@sidgaikwad is attempting to deploy a commit to the Unlayer Team on Vercel.

A member of the Team first needs to authorize it.

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.

No SSR / Next.js App Router smoke test despite the documented use client guarantee

1 participant