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:(Form):Problem with parse translation message in issues use Valibot in form #1783

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ncodealex
Copy link

πŸ”— Linked issue

Resolves #1782

❓ 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)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This pull request solves the problem with translations messages in valibot

πŸ“ Checklist

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

@ncodealex ncodealex marked this pull request as draft May 12, 2024 22:44
@ncodealex ncodealex marked this pull request as ready for review May 12, 2024 22:46
import type { ObjectSchemaAsync as ValibotObjectSchema } from 'valibot'
import {
type ObjectSchemaAsync as ValibotObjectSchema,
safeParseAsync as ValibotParseAsync
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't have a direct import to valibot here, because we don't want to include it as a dependency (See this PR: #617), that's why we used ._parse in the first place. We need to find another way around.

Copy link
Author

@ncodealex ncodealex May 14, 2024

Choose a reason for hiding this comment

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

Thanks for answer, do you can see comment @fabien-hiller in issue ?

#1782 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

In PR #617 valibot is not included in dependencies:

@nuxthq/ui/v/2.7.0

Now valibot included:

last version @nuxt/ui

I'm sorry, i try explore in details this question

Copy link
Collaborator

@noook noook May 14, 2024

Choose a reason for hiding this comment

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

What he meant is as long as no direct import to this dependency is done (except for import type) valibot is not included in the build. I believe you can bypass this import by using a dynamic import in your function like this:

Suggested change
safeParseAsync as ValibotParseAsync

See https://github.com/nuxt/ui/pull/1783/files#r1599592678

Copy link
Author

@ncodealex ncodealex May 14, 2024

Choose a reason for hiding this comment

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

What he meant is as long as no direct import to this dependency is done (except for import type) valibot is not included in the build. I believe you can bypass this import by using a dynamic import in your function like this:

See https://github.com/nuxt/ui/pull/1783/files#r1599592678

Oh, thanks! I check it later and return with answer!

@@ -264,7 +267,7 @@ async function getValibotError (
state: any,
schema: ValibotObjectSchema<any>
): Promise<FormError[]> {
const result = await schema._parse(state)
const result = await ValibotParseAsync(schema, state)
Copy link
Collaborator

@noook noook May 14, 2024

Choose a reason for hiding this comment

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

I'm not sure if that works after building

Suggested change
const result = await ValibotParseAsync(schema, state)
const { safeParseAsync } = await import('valibot')
const result = await safeParseAsync(schema, state)

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.

Problem with error message translations if use valibot in form
4 participants