Skip to content

fix(loggerCodeViewer): avoid replaceChildren() so the viewer renders under Lightning Locker - #1038

Open
yassine2med wants to merge 1 commit into
jongpie:mainfrom
yassine2med:fix/code-viewer-locker-replace-children
Open

yassine2med wants to merge 1 commit into
jongpie:mainfrom
yassine2med:fix/code-viewer-locker-replace-children

Conversation

@yassine2med

Copy link
Copy Markdown

In orgs with Lightning Web Security disabled, Lightning Locker wraps DOM elements in SecureElement proxies, which do not implement replaceChildren(). Since v4.19.0 _renderPrismHtml() called container.replaceChildren(preElement), so it threw replaceChildren is not a function and no code was rendered on the LogEntry__c page or in the View Full Source modal.

This clears the container with innerHTML = '' and then calls appendChild(), the same approach v4.18.4 and earlier used.

Tests: added a regression test to loggerCodeViewer.test.js that removes Element.prototype.replaceChildren. It fails on the old code (container.replaceChildren is not a function) and passes now. All 19 LWC suites (337 tests) pass and prettier is clean. I could not run the Apex tests or check a Locker org myself.

Fixes #1034

🤖 Generated with Claude Code

https://claude.ai/code/session_01CakWWNeSCYx1PiJnozyrTB

…under Lightning Locker

Lightning Locker's SecureElement proxy does not implement replaceChildren(), so _renderPrismHtml() threw and no code was rendered in orgs with LWS disabled (v4.19.0+). Clear the container with innerHTML = '' and appendChild() instead. Adds a regression test that removes Element.prototype.replaceChildren; it fails with the old code and passes now. Fixes jongpie#1034
@yassine2med
yassine2med requested a review from jongpie as a code owner November 18, 2026 23:45

This branch has not been deployed

No deployments
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.

loggerCodeViewer fails under Lightning Locker: replaceChildren is not a function (v4.19.0+)

1 participant