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

[v0.31.0-rc.5] Invalid type: Expected Object but received Object because of edge runtime #602

Closed
ammarriq opened this issue May 25, 2024 · 3 comments
Assignees
Labels
bug Something isn't working external Problem has external origin question Further information is requested

Comments

@ammarriq
Copy link

ammarriq commented May 25, 2024

Valibot object schema doesn't seem to work with edge runtime

Steps to reproduce;

  1. install nextjs with valibot v31
  2. paste the code in page.tsx
    const schema = object({
        name: string(),
    })
    parse(schema, { name: 'Ammar' })
  3. add the statement at the top of file;
    export const runtime='edge'

it will throw an error;
Error: Invalid type: Expected Object but received Object

it should also throw an error for other frameworks optiong into edge runtime

@ammarriq ammarriq changed the title v31 doesn't work with edge runtime [v31] Invalid type: Expected Object but received Object because of edge runtime May 25, 2024
@ammarriq ammarriq changed the title [v31] Invalid type: Expected Object but received Object because of edge runtime [v31] Invalid type: Expected Object but received Object because of edge runtime May 25, 2024
@ammarriq ammarriq changed the title [v31] Invalid type: Expected Object but received Object because of edge runtime [v0.31.0-rc.5] Invalid type: Expected Object but received Object because of edge runtime May 25, 2024
@fabian-hiller
Copy link
Owner

Thanks for reporting and thanks for the reproduction steps. I will have a look at it later.

@fabian-hiller fabian-hiller self-assigned this May 25, 2024
@fabian-hiller fabian-hiller added the bug Something isn't working label May 25, 2024
@fabian-hiller
Copy link
Owner

fabian-hiller commented May 27, 2024

I have submitted a bug report: vercel/edge-runtime#899

There are other problems with the current plain object check, for example in #587, but I am not sure if Valibot is the problem. Normally, this should not be a problem. We could remove the input.constructor === Object check to make it less strict, but then any object that is not null will be accepted. In practice, this is usually not a problem because we never return the original object. So, strictly speaking, the validation is still safe. Therefore, I might make the validation less strict so as not to have to deal with special JS runtime behavior that we can't control.

One problematic case that just came to my mind that could lead to unexpected behavior is our looseObject and objectWithRest schemas, as they can add unexpected data to the output if the wrong object types are passed.

@fabian-hiller
Copy link
Owner

This is fixed in v0.31.0-rc.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external Problem has external origin question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants