marilari88 / zod-playground

Play with Zod schema validation
https://zod-playground.vercel.app
MIT License
31 stars 1 forks source link

Make the current schema/values shareable among users #20

Closed marilari88 closed 3 months ago

marilari88 commented 4 months ago

For this purpose we could move the state to the URL query strings or alternatively rely on a database: the first option is less complicated but implies to implement an escaping/encoding phase when write/read the url and we must ensure the URL can contain the whole state Additionally we could evaluate if add a proper share button/menu makes sense

DanielBaulig commented 4 months ago

Was looking for a way to share a reproducible bug in zod in a bug report. Having a way to capture schema and input in a shareable URL would be great!

giacomocerquone commented 4 months ago

imho, leave dbs aside and keep it a spa app. I'm preparing a pr for this, shouldn't be that hard to serialize the schema in the url!

I'm working on it 🙂

marilari88 commented 4 months ago

I looked at this task before and I agree there are no concerns about the url length limitation. By relying to the search params we make the actual state reduntant, and as consequence some refactoring is unavoidable Considering I already started working on it, I'll be happy to receive your review @giacomocerquone

giacomocerquone commented 4 months ago

I looked at this task before and I agree there are no concerns about the url length limitation. By relying to the search params we make the actual state reduntant, and as consequence some refactoring is unavoidable Considering I already started working on it, I'll be happy to receive your review @giacomocerquone

Ok, it makes sense. I'll have a look at it then.

I'm a bit concerned about what you said, though. The state is not redundant, the URL has to be treated as an initial value of the internal state. They're two different things, and the state should stay.

giacomocerquone commented 4 months ago

Some other things I thought about:

  1. I've read that there is a current limit of 2.048 characters to be used in the URL. While this might not be problematic, think about showing up a warning (modal) if the schema is longer than that.
  2. Also, should we also share the value? It might be useful, and it would be weird to only share the schema if a particular value is needed to test it out.
  3. Lastly, we could use GitHub auth and gists to share the value. It should be possible to do everything without hosting a server
marilari88 commented 4 months ago

Some other things I thought about:

  1. I've read that there is a current limit of 2.048 characters to be used in the URL. While this might not be problematic, think about showing up a warning (modal) if the schema is longer than that.
  2. Also, should we also share the value? It might be useful, and it would be weird to only share the schema if a particular value is needed to test it out.
  3. Lastly, we could use GitHub auth and gists to share the value. It should be possible to do everything without hosting a server
  1. I read that this limit is related to search engines, but we don't care about it. Based on what I've read, the limit depends on the browser, and luckily, modern browsers allow handling longer URLs.
  2. Yes, we must also share values.
  3. I hadn't thought of this smart solution. Thank you for sharing. I will consider it in case we realize we have a problem with URL length.

So, the plan is as follows: