[FIX] sap/base/util/deepEqual: guard browser-global Node reference#4451
Open
martindglaser wants to merge 1 commit into
Open
[FIX] sap/base/util/deepEqual: guard browser-global Node reference#4451martindglaser wants to merge 1 commit into
martindglaser wants to merge 1 commit into
Conversation
deepEqual() compared DOM nodes via `a instanceof Node`. `Node` is a browser global that does not exist in non-browser environments such as Web Workers or Node.js, so deepEqual() threw a ReferenceError there when comparing any two objects - even though it belongs to the environment-agnostic sap/base package (as the existing @evo-todo already notes). Guard the reference with a typeof check so DOM nodes are still compared in the browser while deepEqual stays usable in environments without a 'Node' global.
Contributor
|
Hello @martindglaser, Thank you for creating this PR — much appreciated! 🙌 I've created internal incident DINC0976821 to track this. Colleagues responsible for this module will look it up soon. Regards, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sap/base/util/deepEqualcompares DOM nodes viaa instanceof Node.Nodeis a browser global that does not exist in non-browser environments such as Web Workers or Node.js, sodeepEqual()throws aReferenceError: Node is not definedthere when comparing any two objects — even though it is part of the environment-agnosticsap/basepackage. The module's own@evo-todoalready flags this ("dependency to global name 'Node' contradicts sap/base package"). This complements the recent removal ofwindowusages fromsap/base(6601e5b), which did not coverNode.Fix
Guard the reference with
typeof Node !== "undefined"so DOM nodes are still compared in the browser whiledeepEqualstays usable in environments without aNodeglobal. No behavior change in the browser (public API unchanged).How to reproduce
In a Web Worker or Node.js context: