Skip to content

Conversation

@OrbisK
Copy link
Member

@OrbisK OrbisK commented Nov 1, 2025

Caution

Breaking change

🔗 Linked issue

fixes #33623

📚 Description

This simplifies the usage for useAsyncData handlers.

@OrbisK OrbisK requested a review from danielroe as a code owner November 1, 2025 22:10
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Nov 1, 2025

Walkthrough

The PR changes the AsyncDataHandler<ResT> signature from two positional parameters (nuxtApp, options: { signal }) to a single context object (context: { signal, nuxtApp }). Call sites in the async data composable, fetch composable and related tests have been updated to pass and destructure this single context object. Abort signal handling remains via context.signal. The public type export and documentation examples were updated to reflect the new handler shape.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes follow a consistent refactor pattern across multiple files (type, composables, tests).
  • Review should verify all call sites pass { signal, nuxtApp } correctly and that nuxtApp is extracted where needed (prerender/cache logic in asyncData.ts).
  • Confirm exported AsyncDataHandler type and documentation examples are updated and consistent.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "feat!: simplify useAsyncData() handler signature" is clear, concise, and directly related to the main change in the changeset. The title accurately captures the primary objective of refactoring the AsyncDataHandler signature from separate parameters to a single context object. It follows conventional commits format with the breaking change indicator (!), and avoids vague terminology or excessive detail. A developer scanning the history would immediately understand that this PR simplifies the useAsyncData handler interface.
Linked Issues Check ✅ Passed The code changes fully implement the objective specified in linked issue #33623. The AsyncDataHandler type signature has been updated from (nuxtApp: NuxtApp, options: { signal: AbortSignal }) to (context: { signal: AbortSignal, nuxtApp: NuxtApp }) across all relevant files. All internal call sites in asyncData.ts and fetch.ts have been updated to pass the new context object format, documentation examples have been revised, and tests have been updated accordingly. The implementation directly addresses the issue's requirement to simplify the handler signature by consolidating parameters into a single object.
Out of Scope Changes Check ✅ Passed All code changes are directly scoped to the objective of simplifying the AsyncDataHandler signature. The modifications span documentation (use-async-data.md), implementation files (asyncData.ts and fetch.ts), and tests (use-async-data.test.ts), with every change either updating the handler signature itself, adapting call sites to the new signature, or updating documentation and tests to reflect the change. No extraneous modifications or tangential improvements are present in the changeset.
Description Check ✅ Passed The pull request description is related to the changeset, stating that it "simplifies the usage for useAsyncData handlers" and linking to the relevant issue #33623. Whilst minimal in detail, the description appropriately captures the intent of the changes and provides the necessary context linking to the GitHub issue. The description meets the lenient pass criteria for this check as it is clearly on-topic and describes a genuine aspect of the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 911b3cf and 2e570fc.

📒 Files selected for processing (4)
  • docs/3.api/2.composables/use-async-data.md (7 hunks)
  • packages/nuxt/src/app/composables/asyncData.ts (3 hunks)
  • packages/nuxt/src/app/composables/fetch.ts (1 hunks)
  • test/nuxt/use-async-data.test.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nuxt/src/app/composables/fetch.ts
  • docs/3.api/2.composables/use-async-data.md
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • test/nuxt/use-async-data.test.ts
  • packages/nuxt/src/app/composables/asyncData.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • test/nuxt/use-async-data.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-10T14:42:56.647Z
Learnt from: Tofandel
Repo: nuxt/nuxt PR: 33192
File: test/nuxt/use-async-data.test.ts:366-373
Timestamp: 2025-09-10T14:42:56.647Z
Learning: In the Nuxt useAsyncData test "should watch params deeply in a non synchronous way", the foo watcher intentionally updates both params.foo and params.locale using locale.value, simulating a scenario where one watcher consolidates multiple reactive values into a shared params object for testing debounced/non-synchronous behavior.

Applied to files:

  • test/nuxt/use-async-data.test.ts
  • packages/nuxt/src/app/composables/asyncData.ts
🧬 Code graph analysis (1)
packages/nuxt/src/app/composables/asyncData.ts (1)
packages/nuxt/src/app/nuxt.ts (1)
  • NuxtApp (199-199)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (7)
test/nuxt/use-async-data.test.ts (4)

955-969: LGTM: Handler signature correctly updated.

The test properly validates that the handler receives the signal in the context object and that it can be aborted via clear().


1002-1027: LGTM: Signal merging test properly updated.

The handler correctly destructures the signal from the context object. The test validates that multiple abort signals can be merged, which is important for external cancellation scenarios.


1084-1104: LGTM: Dedupe cancellation with abort properly tested.

The handler correctly receives and uses the signal from the context object. The test validates that the first request is properly aborted when dedupe: 'cancel' is used.


1136-1155: LGTM: Clear abort behaviour correctly validated.

The handler properly destructures the signal from the context object and the test confirms that calling clear() triggers the abort signal, setting the status to idle.

packages/nuxt/src/app/composables/asyncData.ts (3)

20-20: Breaking change: Handler signature simplified.

The new signature consolidates nuxtApp and the options object into a single context parameter, which aligns with the PR objectives to simplify the handler signature and facilitate signal integration.


651-662: LGTM: Prerender wrapper correctly updated.

The wrapper properly adapts to the new signature by accepting a single ctx parameter, destructuring nuxtApp for cache operations, and forwarding the complete context (including signal) to the underlying handler.


707-726: LGTM: Handler invocation correctly updated.

The handler is properly invoked with a single context object containing both signal (with merged abort signals including timeout) and nuxtApp. The implementation correctly handles abort scenarios before and during execution.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 1, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33629

nuxt

npm i https://pkg.pr.new/nuxt@33629

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33629

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33629

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33629

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33629

commit: 2e570fc

@OrbisK OrbisK force-pushed the feat/async-data-handler branch from 911b3cf to 2e570fc Compare November 1, 2025 22:16
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 1, 2025

CodSpeed Performance Report

Merging #33629 will not alter performance

Comparing OrbisK:feat/async-data-handler (2e570fc) with main (89f59b7)

Summary

✅ 10 untouched

Copy link
Member

@huang-julien huang-julien left a comment

Choose a reason for hiding this comment

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

Let's use a future flag to make the breaking change for v5

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.

refactor useAsyncData handler params

3 participants