Skip to content
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

fix: proper runtimeConfig and publicRuntimeConfig declaration #950

Merged
merged 9 commits into from
Nov 7, 2023

Conversation

AndreyYolkin
Copy link
Contributor

πŸ”— Linked issue

Resolves #948

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR backports schema generation approach from https://github.com/nuxt/nuxt/blob/4b2608c74d80551eee857ab74ab470da839894f9/packages/nuxt/src/core/templates.ts#L132, which introduces next fixes/features:

  1. Runtime Config (and its public part) now has more accurate types, generated with Untyped
  2. $config in Vue templates is declared with the same generated type

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Before:

image image

After:

image

(Untyped has some struggles with array types, not Nuxt itself issue):
image

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

This is great! I wonder if we ned to do this in a separate template so we can do it conditionally on whether nitro is enabled or not as I think the runtimeConfig has a different format if it's disabled.

@AndreyYolkin
Copy link
Contributor Author

Wise enough. I'll take another round of refactoring to ensure it has support for nitro-less build

@danielroe danielroe marked this pull request as draft November 2, 2023 17:40
@danielroe
Copy link
Member

(converting to draft just for more obvious triage - feel free to mark ready any time you feel like it)

' interface NuxtAppCompat {',
' $config: RuntimeConfig',
' }',
' interface NuxtRuntimeConfig extends RuntimeConfig {}',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really know about this: we can use

const { $config } = useNuxtApp()

const { nuxt2Context: { $config } } = useNuxtApp()

but displayed types will be different

Copy link
Collaborator

@wattanx wattanx left a comment

Choose a reason for hiding this comment

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

Nice! Looks good to me!

@AndreyYolkin AndreyYolkin marked this pull request as ready for review November 7, 2023 14:35
@danielroe
Copy link
Member

Beautiful work! In future we likely need to add a type test and confirm that useRuntimeConfig() works properly (right now it seems to be shadowed by Nitro auto-import).

@danielroe danielroe merged commit 573b738 into nuxt:main Nov 7, 2023
9 checks passed
This was referenced Nov 7, 2023
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.

Runtime config is not properly typed in runtime
3 participants