Skip to content

fix(nuxt): generate correct types for async data defaults based on nuxt.config #32324

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 5 commits into from
Jun 10, 2025

Conversation

DamianGlowala
Copy link
Member

🔗 Linked issue

resolves #32213

📚 Description

Correctly generates types for chosen async data/data error value when v4 compat mode is enabled.

@Copilot Copilot AI review requested due to automatic review settings June 6, 2025 16:55
@DamianGlowala DamianGlowala requested a review from danielroe as a code owner June 6, 2025 16:55
Copy link

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

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the generation of types for async data defaults to correctly use the configured values when v4 compatibility mode is enabled.

  • Updated the type generation logic in Nuxt templates for async data and error value defaults based on nuxt.config settings.
  • Introduced nested ternary expressions to select between null and undefined for v4 compatibility.
Comments suppressed due to low confidence (1)

packages/nuxt/src/core/templates.ts:108

  • In non-v4 mode, the default now returns 'undefined' instead of the previous 'null'. Please verify that this behavior aligns with the intended API design.
type DefaultAsyncDataErrorValue = ${ isV4 ? ctx.nuxt.options.experimental.defaults.useAsyncData.errorValue === 'null' ? null : undefined : undefined }

Comment on lines 106 to 114
return `
declare module 'nuxt/app/defaults' {
type DefaultAsyncDataErrorValue = ${isV4 ? 'undefined' : 'null'}
type DefaultAsyncDataValue = ${isV4 ? 'undefined' : 'null'}
type DefaultAsyncDataErrorValue = ${
isV4
? ctx.nuxt.options.experimental.defaults.useAsyncData.errorValue === 'null'
? null
: undefined
: undefined
}
Copy link
Preview

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

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

[nitpick] The nested ternary operator here reduces readability; consider refactoring by extracting the logic into a helper or using clearer conditional constructs.

Copilot uses AI. Check for mistakes.

Copy link

pkg-pr-new bot commented Jun 6, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: b09facd

Copy link

codspeed-hq bot commented Jun 6, 2025

CodSpeed Performance Report

Merging #32324 will not alter performance

Comparing fix/async-data-defaults-types (b09facd) with 3.x (eebb756)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe merged commit 6b99c0d into 3.x Jun 10, 2025
86 of 87 checks passed
@danielroe danielroe deleted the fix/async-data-defaults-types branch June 10, 2025 14:23
@github-actions github-actions bot mentioned this pull request Jun 9, 2025
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy