Skip to content

Deep merge props #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025
Merged

Deep merge props #213

merged 3 commits into from
Apr 12, 2025

Conversation

skryukov
Copy link
Contributor

@skryukov skryukov commented Apr 10, 2025

This PR adds support for deep merge props.

See inertiajs/inertia-laravel#679 and inertiajs/inertia#2069

@skryukov skryukov marked this pull request as ready for review April 10, 2025 08:25
@@ -4,23 +4,35 @@ By default, Inertia overwrites props with the same name when reloading a page. H

## Server side

To specify that a prop should be merged, you can use the `merge` method on the prop value.
> `deep_merge` requires `@inertiajs/core` v2.1.0 or higher, and `inertia_rails` v3.8.0 or higher.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version numbers are subject to change 😂

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget it 😂 it's 2.0.8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks @HichemTab-tech!

@skryukov skryukov changed the title Deep merge Deep merge props Apr 10, 2025
@skryukov skryukov force-pushed the deep-merge branch 2 times, most recently from 9e54c92 to 6288dcf Compare April 10, 2025 19:35
Copy link
Collaborator

@bknoles bknoles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

On the client side, Inertia detects that this prop should be merged. If the prop returns an array, it will append the response to the current prop value. If it's an object, it will merge the response with the current prop value.
On the client side, Inertia detects that this prop should be merged. If the prop returns an array, it will append the response to the current prop value. If it's an object, it will merge the response with the current prop value. If you have opted to `deepMerge`, Inertia ensures a deep merge of the entire structure.

**Of note:** During the merging process, if the value is an array, the incoming items will be _appended_ to the existing array, not merged by index.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good callout!

@bknoles bknoles merged commit b2e959e into inertiajs:master Apr 12, 2025
18 checks passed
@skryukov skryukov deleted the deep-merge branch April 12, 2025 21:13
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