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

Error thrown on Custom form submit #2946

Closed
BALEHOK opened this issue Mar 14, 2022 · 5 comments · Fixed by #3019
Closed

Error thrown on Custom form submit #2946

BALEHOK opened this issue Mar 14, 2022 · 5 comments · Fixed by #3019
Assignees
Labels
bug Something isn't working triage
Milestone

Comments

@BALEHOK
Copy link
Contributor

BALEHOK commented Mar 14, 2022

Steps:

  1. Add "Show a modal or sidebar form" brick.
  2. Invoke the extension, fill the form and Submit.

Expected:
Form is submitted successfully, the 'data' logged to the console.

Actual:
An error is logged in the console, the data is undefined.

image

Error compiling schema, function code: var refVal1 = refVal[1]; var validate = function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict';  var vErrors = null;  var errors = 0;      if (rootData === undefined) rootData = data;      var errs_1 = errors;    var errs_2 = errors; if ((typeof data !== "number" || (data % 1) || data !== data)) {  var err =  { keyword: 'type' , dataPath: (dataPath || '') + "" , schemaPath: '#/definitions/nonNegativeInteger/type' , params: { type: 'integer' }  , message: 'should be integer'  } ;  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++;  }  if ((typeof data === "number")) {    if (  data < 0 || data !== data) {  var err =  { keyword: 'minimum' , dataPath: (dataPath || '') + "" , schemaPath: '#/definitions/nonNegativeInteger/minimum' , params: { comparison: '>=', limit: 0, exclusive: false }  , message: 'should be >= 0' } ;  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++;  }   }  var valid2 = errors === errs_2;   var valid1 = errors === errs_1;   validate.errors = vErrors;  return errors === 0;        }; return validate;
{
    "data": undefined,
    "context": {
        "extensionPointId": "@internal/de6188b5041b1f74fdd1367df93bc08cc622b9ff",
        "label": "Modal form",
        "extensionId": "1846ba01-5c00-40f2-a4b4-9baf74e999ea"
    }
}

Extension export YAML:

apiVersion: v3
kind: recipe
metadata:
  id: ""
  name: Modal form
  description: Blueprint exported from PixieBrix
  version: 1.0.0
definitions:
  extensionPoint:
    kind: extensionPoint
    definition:
      type: menuItem
      reader:
        - "@pixiebrix/document-metadata"
      isAvailable:
        matchPatterns:
          - "*://*/*"
        urlPatterns: []
        selectors: []
      containerSelector: div:has(> a:contains("Tour"))
      position: append
      template: "<a href=\"#\" style=\"color: orange\">{{{ caption }}}</a>"
extensionPoints:
  - id: extensionPoint
    label: Modal form
    services: {}
    config:
      caption: Show form
      action:
        - id: "@pixiebrix/form-modal"
          config:
            schema:
              title: Example Form
              type: object
              properties:
                example:
                  title: Example Field
                  type: string
                  description: An example form field
            uiSchema:
              ui:order:
                - example
                - "*"
            cancelable: true
            submitCaption: Submit
            location: modal
          outputKey: form
      dynamicCaption: false
@BALEHOK BALEHOK added the bug Something isn't working label Mar 14, 2022
@twschiller
Copy link
Contributor

twschiller commented Mar 15, 2022

Thanks for reporting @BALEHOK. Could you export the extension where you were seeing this problem? We need to understand it a bit better to triage

@twschiller twschiller added this to the 1.5.7 milestone Mar 15, 2022
@twschiller twschiller modified the milestones: 1.5.7, 1.5.8 Mar 16, 2022
@BALEHOK
Copy link
Contributor Author

BALEHOK commented Mar 17, 2022

Thanks for reporting @BALEHOK. Could you export the extension where you were seeing this problem? We need to understand it a bit better to triage

Added to the description.

@twschiller
Copy link
Contributor

@BALEHOK I'm not able to reproduce this with the blueprint provided. Could you ensure you've run npm install and try again? If it's still happening for you could you reach out the @BLoe to see if he can reproduce it?

@BALEHOK
Copy link
Contributor Author

BALEHOK commented Mar 23, 2022

@BLoe confirmed he also see the error.
Just in case, it's thrown by the content script, reported in the DevTools of the website (not the DevTools of the PageEditor)

@BALEHOK
Copy link
Contributor Author

BALEHOK commented Mar 24, 2022

The error is thrown in ajv validator, called by react-jsonschema-form at https://github.dev/rjsf-team/react-jsonschema-form/blob/6063bce42fc3faec5710a67d2671aa5123239feb/packages/core/src/validate.js#L208

The original error (normally swallowed by the rjsf):

validation error es EvalError: 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' https://apis.google.com http://localhost:8097".

    at new Function (<anonymous>)
    at Ajv.localCompile (vendors.js:15965:26)
    at Ajv.resolve (vendors.js:16297:19)
    at Object.resolveRef (vendors.js:16034:21)
    at Object.generate_ref [as code] (vendors.js:19563:22)
    at Object.generate_validate [as validate] (vendors.js:20332:37)
    at Object.generate_properties [as code] (vendors.js:19305:26)
    at generate_validate (vendors.js:20429:35)
    at localCompile (vendors.js:15933:22)
    at Ajv.compile (vendors.js:15900:13)

As stated by ajv the unsafe-eval should be enabled to run the validator or the schemas must be precompiled (you can start reading from here)

@twschiller twschiller modified the milestones: 1.5.9, 1.5.10 Mar 29, 2022
twschiller added a commit that referenced this issue Mar 30, 2022
twschiller added a commit that referenced this issue Mar 30, 2022
Co-authored-by: Todd Schiller <todd.schiller@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants