feat(inertia): add merge props with merge(), prepend(), and deepMerge()#1932
Merged
Conversation
🦋 Changeset detectedLatest commit: e005fd2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1932 +/- ##
==========================================
+ Coverage 91.90% 91.98% +0.08%
==========================================
Files 115 115
Lines 3991 4032 +41
Branches 1031 1047 +16
==========================================
+ Hits 3668 3709 +41
Misses 287 287
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
@ashunar0 Nice! Thank you! |
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
Third step of the
@hono/inertiav3 protocol breakdown: ③ Merge props, built on top of the partial reload foundation from #1904.Adds three helpers —
merge(),prepend(), anddeepMerge()— that mark a prop for client-side combination on the next partial reload, instead of the default replace behavior. The wrapped value travels as-is; the renderer advertises which keys to combine via the newpage.mergeProps/page.prependProps/page.deepMergePropsarrays and emits dot-paths onpage.matchPropsOnfor the client's dedupe logic.Protocol behaviour
page.mergeProps/prependProps/deepMergeProps/matchPropsOnemitted on every response (initial + partial) so the client knows which keys to combine on the next partial reloadonly/exceptmergePropsetc.)merge()(e.g.merge(() => fetchPosts(), ...))Merging itself only takes effect on subsequent partial reloads — full page visits always replace props entirely (matches the upstream protocol).
Implementation
merge<T>(data, { matchOn? }): T,prepend<T>(...),deepMerge<T>(...)return opaque markers (Symbol.for('@hono/inertia/merge')) that the renderer unwraps. The return type isT, so call sites andTypedResponsestay transparent — mirrors thedefer()pattern from feat(inertia): add deferred props with defer() #1911.matchOnaccepts a string or array; entries are emitted as"<propKey>.<field>"onpage.matchPropsOn(e.g.merge(posts, { matchOn: 'id' })⇒matchPropsOn: ['posts.id']).PageObjectgains four optional fields —mergeProps?: string[],prependProps?: string[],deepMergeProps?: string[],matchPropsOn?: string[]— emitted only when at least one prop in the response carries the corresponding marker.Scope intentionally kept small (single PR per protocol feature, like #1904 / #1911):
Test plan