payloadcms / payloadcms/payload

Admin Panel SSR Error: document.createTextNode is not a function

Open
#15,124 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale status: needs-repro
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Bug Report

Describe the Bug

The Payload admin panel returns a 500 error with TypeError: document.createTextNode is not a function during server-side rendering. This prevents the entire admin panel from loading.

Payload Version
  • Tested on: 3.68.5, 3.69.0, 3.70.0 (issue persists across all versions)
Adapters and Plugins
  • @payloadcms/db-postgres
  • @payloadcms/richtext-lexical
  • @payloadcms/plugin-multi-tenant
  • @payloadcms/plugin-seo
  • @payloadcms/plugin-nested-docs
  • @payloadcms/plugin-redirects
Error Message
TypeError: document.createTextNode is not a function
    at <unknown> (.next/server/app/(payload)/admin/[[...segments]]/page.js:7:107202)
    at 18225 (.next/server/app/(payload)/admin/[[...segments]]/page.js:7:107221)
    at Object.c [as require] (.next/server/webpack-runtime.js:1:143)
Steps to Reproduce
  1. Set up Payload CMS with Next.js 15 (standalone output)
  2. Use the default Lexical rich text editor
  3. Configure multiple collections with richText fields
  4. Navigate to /admin
  5. Admin panel fails with 500 error
Expected Behavior

Admin panel should load normally.

Root Cause Analysis

Lexical editor code that uses DOM APIs (document.createTextNode) is being bundled into the server-side admin page. When Next.js attempts to SSR the admin panel, this code executes on the server where document doesn't have the expected methods.

What I've Tried
  • Different Payload versions (3.68.5, 3.69.0, 3.70.0)
  • Changed all value imports to type imports: import type { ... }
  • Removed unused Lexical imports from plugins/index.ts
  • Disabled custom admin components
  • Removed devBundleServerPackages: false from withPayload config
  • Regenerated importMap multiple times
  • Full Docker rebuild with image deletion

None of these resolved the issue.

Environment
  • Next.js: 15.4.10
  • Node.js: 22.17.1
  • Database: PostgreSQL 16
  • Deployment: Docker (standalone output)
  • OS: Linux (WSL2)
Related
  • facebook/lexical#4960 (Lexical SSR limitations)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure at /admin with Next.js 15 standalone output and inspect the generated .next/server/app/(payload)/admin/[[...segments]]/page.js bundle. Trace which default Lexical rich text editor code reaches server-side rendering; done means the admin panel loads without the document.createTextNode error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, node.js, postgres, typescript
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.