Skip to content

Document.compatMode is undefined (KaTeX treats as quirks mode) #2267

Description

@steve02081504

Summary

Document.compatMode is missing (undefined) on happy-dom documents.

Browsers expose either "CSS1Compat" (standards) or "BackCompat" (quirks). Libraries such as KaTeX treat anything other than "CSS1Compat" as quirks mode and emit:

Warning: KaTeX doesn't work in quirks mode. Make sure your website has a suitable doctype.

Repro

import { Window } from 'happy-dom'

const window = new Window({ url: 'http://localhost/' })
console.log(window.document.compatMode) // → undefined (expected: "CSS1Compat" or "BackCompat")

window.document.write('<!DOCTYPE html><html><head></head><body></body></html>')
console.log(window.document.compatMode) // still undefined even with a doctype present

Seen with happy-dom@15 under Deno.

Suggested fix

Implement Document.compatMode per HTML / DOM:

  • "CSS1Compat" when the document has an HTML doctype (or is XML)
  • "BackCompat" otherwise

Happy to test a PR.

Consumer note (steve02081504/fount): Markdown pure tests shim compatMode to 'CSS1Compat' until this lands; remove that override after a happy-dom release that implements it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions