Skip to content

feat: add shared deepMerge helper to component-base (CP: 24.10) (#12496) (CP: 24.9) - #12559

Merged
web-padawan merged 1 commit into
24.9from
cherry-pick-12496-to-24.9-1788179634250
Aug 31, 2026
Merged

web-padawan merged 1 commit into
24.9from
cherry-pick-12496-to-24.9-1788179634250

Conversation

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This PR cherry-picks changes from the original PR #12496 to branch 24.9.


Original PR description

This PR cherry-picks changes from the original PR #12493 to branch 24.10.


This PR cherry-picks changes from the original PR #12483 to branch 25.1.


Two packages carried their own private deep merge implementation: one in
packages/charts/src/helpers.js and one in I18nMixin. They were near
duplicates, but not quite. The charts version assigned nullish values and
shared arrays with the source, while the I18nMixin version skipped nullish
values and copied arrays, so that an i18n object providing only some of the
properties does not remove the others. Neither had tests of its own.

This adds one documented helper in component-base and removes both copies.

packages/component-base/src/object-utils.js exports two functions:

  • deepMerge(target, source) merges a single source and assigns values as they
    are. Used by the chart mixins.
  • deepMergePartials(target, ...sources) merges several sources in order,
    skips nullish values and copies arrays. Used by I18nMixin, which keeps its
    current behaviour.

Both ignore __proto__, constructor and prototype keys in the source, and
never continue a merge into an object reached through the prototype chain, so
that merging an object provided by an application can not modify
Object.prototype.

deepMerge changes behaviour in two ways:

  • When a property of the target is not a plain object and the source has an
    object for the same key, the target property is now replaced with the merged
    object. Previously the source subtree was dropped. With an invalid chart
    configuration this can replace an array from the base config with an object,
    where the array used to survive.
  • Only an object that inherits from Object.prototype or from nothing is
    merged. A value such as a Date, a Map or a class instance is now assigned
    as it is, where both previous implementations replaced it with an empty
    object.

deepMergePartials() keeps the behaviour of the I18nMixin implementation it
replaces: a property that the target already has is not replaced with an
object, so that a custom i18n value of an unexpected type does not remove a
default.

deepMerge stays exported from packages/charts/src/helpers.js as a
deprecated re-export, so deep imports keep working.


🤖 Generated with Claude Code

@sonarqubecloud

Copy link
Copy Markdown

@web-padawan
web-padawan merged commit e00c792 into 24.9 Aug 31, 2026
10 of 11 checks passed
@web-padawan
web-padawan deleted the cherry-pick-12496-to-24.9-1788179634250 branch August 31, 2026 13:38
@vaadin-bot

Copy link
Copy Markdown
Collaborator Author

This ticket/PR has been released with Vaadin 24.9.21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants