-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Dynamically precompile schemas: Error: compileSchemaValidators is not a function. #4012
Comments
@magaton the reason you get However, there is a bigger issue about the code you have - the part: const code = compileSchemaValidatorsCode(schema, options); is supposed to be running server side, somewhere like api endpoint returning |
Thanks @zxbodya! If I do import as you suggest:
I am getting the following error:
If it is not too much to ask, would it be possible to provide a sample project / codesandbox that:
Thanks in advance |
To clarify - why you are looking into precompiled schema validators, is it because you are trying to enforce the content security policy blocking unsafe-eval, and not allowing it to generate validators in the browser? if not - you probably do not need to precompile the schama… you can just import Then, if you need to precompile it - do you need to do that dynamically? If your schema is static and you do not need to load it from somewhere dynamically - you can precompile it once and then just include it as part of your bundle ("Schema precompilation" / "Using the precompiled validator" - sections in mentioned docs describe exactly this use-case)
you can also use
(that will give correct types)
adopted the code in the docs into nextjs app - https://stackblitz.com/edit/stackblitz-starters-m5wjqy?file=app%2Fpage.tsx |
Thanks very much @zxbodya . What could be the solution? To answer your WHY question :) I want schema to be dynamically precompiled because:
Thanks again! |
the issue is that you are trying to run it in a browser environment, which is not expected and would not work. In the example I shared, this part is running server side in nodejs, and it can not be moved to client-side code
you do not have an issue with CSP? - if so, using I would also not expect much performance difference there using the form, it might only take a bit longer to load - the validator should anyway compile the schema validators just once on load, and not each keystroke… there is probably something else causing performance issues |
Thanks, it is clear then i need to compile schema in browser, not on server side, like you showed. Wrt, your doubt that precompiling schema upfront would help: I want to avoid compiling schemas on each key stroke, since it takes 3-4s. Please correct me if I misunderstood the whole thing. |
@magaton are your schemas changing on the fly? If not, you can simply precompile the schema in your build and simply import it in your code. If it is changing on the fly, are kind of SOL unless you do SSR to compile it on the server |
@heath-freenome , yes, my schemas can change on the fly, but I could live with compiling them on the server side. My understanding, based on this issue seems to be not correct was that schema precompilation is the key for the performance. What I basically need is to eliminate 3-4s long lags after each key stroke. Any advice is much appreciated. |
Prerequisites
What theme are you using?
core
Version
5.x
Current Behavior
I am trying to precompile schemas using the provided code snippets from docs
Expected Behavior
No response
Steps To Reproduce
https://github.com/magaton/rjsf-issues
should help to reproduce.
Environment
Anything else?
Could you please tell me what I am doing wrong?
I need to dynamically precompile schemas when the form is loading since the schema is super complex with lots of
allOf
and dependencies.The text was updated successfully, but these errors were encountered: