Skip to content

Fix: Add null check for cloneOwnerNode in serializeCSSOM#2094

Merged
pranavz28 merged 1 commit intomasterfrom
PER-6656
Jan 19, 2026
Merged

Fix: Add null check for cloneOwnerNode in serializeCSSOM#2094
pranavz28 merged 1 commit intomasterfrom
PER-6656

Conversation

@pranavz28
Copy link
Copy Markdown
Contributor

@pranavz28 pranavz28 commented Jan 16, 2026

Description

Fixes a bug where DOM serialization crashes with "Cannot read properties of null (reading 'sheet')" error when processing stylesheets on complex pages (e.g., Confluence).

Root Cause

In packages/dom/src/serialize-cssom.js, the code attempts to find cloned style elements using querySelector() but does not check if the element exists before passing it to styleSheetFromNode(). When the element is not found in the clone, cloneOwnerNode becomes null, causing the error.

This typically happens with:

  • Style elements in shadow DOM that weren't properly cloned
  • Dynamically inserted styles after initial cloning
  • Complex DOM structures with late-loaded stylesheets
  • Styles in ignored tags

Changes

Code Changes

  • packages/dom/src/serialize-cssom.js: Added null check at line 64 to skip stylesheets when cloneOwnerNode is not found in the cloned DOM

Test Changes

  • packages/dom/test/serialize-css.test.js: Added test case "skips stylesheet when cloneOwnerNode is not found in clone" to verify the fix handles missing elements gracefully

Testing

✅ All existing tests pass (212/212 on Chrome)
✅ New test case validates the fix
✅ Linting passes on modified files

Related

  • Jira: PER-6656
  • Customer: NVIDIA experiencing this error on Confluence pages
  • Workaround: Use ignoreStyleSheetSerializationErrors: true option

Impact

  • Low risk: Only adds a safety check to prevent crashes
  • No breaking changes
  • Improves reliability for complex DOM structures

- Adds null check before calling styleSheetFromNode() to prevent
  'Cannot read properties of null (reading sheet)' error
- Skips stylesheets when cloneOwnerNode is not found in cloned DOM
- Adds test case to verify the fix handles missing elements gracefully

Fixes: PER-6656
@pranavz28 pranavz28 requested a review from a team as a code owner January 16, 2026 08:38
@pranavz28 pranavz28 changed the title Fix: Add null check for cloneOwnerNode in serializeCSSOM (PER-6656) Fix: Add null check for cloneOwnerNode in serializeCSSOM Jan 16, 2026
@pranavz28 pranavz28 merged commit 8ed106d into master Jan 19, 2026
41 checks passed
@pranavz28 pranavz28 deleted the PER-6656 branch January 19, 2026 11:46
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.

3 participants