Skip to content

feat(inertia): add partial reloads support with lazy function props#1904

Merged
yusukebe merged 3 commits into
honojs:mainfrom
ashunar0:feat/inertia-partial-reloads
May 28, 2026
Merged

feat(inertia): add partial reloads support with lazy function props#1904
yusukebe merged 3 commits into
honojs:mainfrom
ashunar0:feat/inertia-partial-reloads

Conversation

@ashunar0

Copy link
Copy Markdown
Contributor

Resolves the first item ("partial reloads") of #1900.

Summary

Adds server-side support for Inertia.js partial reloads:

  • Reads X-Inertia-Partial-Component, X-Inertia-Partial-Data (only), and X-Inertia-Partial-Except headers.
  • Accepts function-valued props that are evaluated lazily, so heavy data fetching is skipped for props that the client did not request.
app.get('/', (c) =>
  c.render('Home', {
    fast: 'inline value',
    slow: () => db.expensiveQuery(), // not invoked when excluded by a partial
  })
)

Scope

This PR sticks to the foundation that the rest of the breakdown in #1900 builds on:

  • only / except props filtering
  • ✅ Lazy function props (() => T | Promise<T>)
  • ✅ Component-mismatch guard: partial headers are ignored when X-Inertia-Partial-Component does not match the rendered component

Deferred to follow-up PRs:

  • ② Deferred props (<Deferred>)
  • ③ Merge / prepend props
  • ④ Infinite scroll
  • always(fn) marker for one-shot props such as flashed messages

Behavior notes

  • A request is treated as a partial reload only when X-Inertia-Partial-Component matches the component being rendered and at least one of X-Inertia-Partial-Data / X-Inertia-Partial-Except is present. Otherwise the request is processed as a normal Inertia visit.
  • The renderer stays fully synchronous when no function-valued prop is present, preserving the existing Response (non-Promise<Response>) return type for the common case.
  • Function props excluded from the partial render are never invoked.

Backward compatibility

Callers that pass only plain values keep the exact same behavior. The new type ResolvedProps<P> awaits the return type of any function-valued prop — plain props are pass-through.

Tests

9 new tests in packages/inertia/src/index.test.ts covering the partial filter, lazy invocation skip, async resolution, component mismatch, whitespace handling, only+except intersection, and the "partial-only header without component" guard.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • yarn changeset at the top of this repo and push the changeset
  • Follow the contribution guide

@changeset-bot

changeset-bot Bot commented May 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0c96f56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/inertia Minor

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

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.08%. Comparing base (8f084ad) to head (0c96f56).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1904      +/-   ##
==========================================
+ Coverage   92.02%   92.08%   +0.05%     
==========================================
  Files         115      115              
  Lines        3936     3965      +29     
  Branches     1013     1025      +12     
==========================================
+ Hits         3622     3651      +29     
  Misses        282      282              
  Partials       32       32              
Flag Coverage Δ
inertia 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/inertia/src/index.ts Outdated

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@yusukebe

Copy link
Copy Markdown
Member

@ashunar0 Thanks! I'll merge.

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.

2 participants