react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Is Precompiled Schema Validation Supported in RJSF 6.0.0-beta.7?

Open WiktorG opened this issue 6 months ago • 5 comments

Prerequisites

What theme are you using?

shadcn

What is your question?

Hi! Thanks for the recent updates—support for shadcn is awesome! 😊

I'm building a Chrome extension and running into the following error:

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".

From what I understand, based on the docs, I need to precompile my schema to avoid eval. However, the example there seems outdated.

First, it shows a TypeScript error indicating it needs more arguments than what's shown in the documentation:

Image

Even if I pass JSONSchema that I used to generate precompiledValidator it throws following error in the browsers console.

Image

Am I doing something the wrong way or is it not supported yet in the 6.0.0-beta.7 version?

Here's a part my package.json

"dependencies": {
     ...
    "@rjsf/core": "6.0.0-beta.7",
    "@rjsf/shadcn": "6.0.0-beta.7",
    "@rjsf/utils": "6.0.0-beta.7",
    "@rjsf/validator-ajv8": "6.0.0-beta.7",
    ...
  },

WiktorG avatar May 11 '25 17:05 WiktorG

@WiktorG You have to precompile the schema on the server and serve it up to the browser. You can't precompile on the browser since the precompilation step actually does the evals. If you have a static schema, then you can precompile it as part of your build process and then simply import it per the documentation.

You did point out some documentation issues, which I am fixing.

heath-freenome avatar May 14 '25 18:05 heath-freenome

@heath-freenome Hi - thanks for the fixes!

Yeah - build process precompilation is what I'm trying to do. I assume that I should be able to do it manually on my computer and then just use it in my project.

WiktorG avatar May 14 '25 18:05 WiktorG

@WiktorG I've set up my npm install to precompile the schema via a postinstall script so that everytime I install/update the project I don't have to remember to recompile the schema.

heath-freenome avatar May 14 '25 19:05 heath-freenome

@WiktorG If you are able to get this working, please close the ticket, otherwise keep asking questions

heath-freenome avatar May 16 '25 19:05 heath-freenome

Hi – I haven't had much time to work lately, but I'll keep you updated, as getting this work is very important in my project.

WiktorG avatar May 28 '25 18:05 WiktorG