projectcaluma / ember-caluma

Ember.js addons for Caluma
https://docs.caluma.io/ember-caluma/
GNU Lesser General Public License v3.0
18 stars 23 forks source link

Form Builder rendering crashes at default answer #2059

Closed StephanH90 closed 2 years ago

StephanH90 commented 2 years ago

I have this issue where the form builder crashes at the point where it is rendering the default answer input (see the crash description below).

This appears due to a babel-plugin-debug-macros bug: https://github.com/ember-cli/babel-plugin-debug-macros/issues/89

Fix

To work around the open issue in babel the assert shouldn't use optional chaining in addon/lib/fieldset.js:

assert(
  "A collection of graphql answers `raw.answers` must be passed",
   raw.answers.every((answer) => /Answer$/.test(answer.__typename))
);

Crash description

Console log:

Error occurred:

- While rendering:
  -top-level
    application
      protected
        qs
          qs.admin-area
            application
              edit
                cfb-form-editor
                  edit.questions
                    edit.questions.edit
                      cfb-form-editor/question
                        validated-form
                          validated-input
                            cfb-form-editor/question/default
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'every')
    at new Fieldset (fieldset.js:43:1)
    at document.js:74:1
    at Array.map (<anonymous>)
    at Document._createFieldsets (document.js:73:1)
    at new Document (document.js:60:1)
    at get field [as field] (default.js:129:1)
    at getPossibleMandatoryProxyValue (index.js:1383:1)
    at _getProp (index.js:1448:1)
    at reference.js:222:1
    at reference.js:170:1

This is the crashing code (ember-form/lib/fieldset.js):

var _raw$form, _raw$answers;

let {
    document,
    raw
} = _ref,
args = _objectWithoutProperties(_ref, _excluded);

(true && !(document) && (0, _debug.assert)("`document` must be passed as an argument", document));
(true && !((raw === null || raw === void 0 ? void 0 : (_raw$form = raw.form) === null || _raw$form === void 0 ? void 0 : _raw$form.__typename) === "Form") && (0, _debug.assert)("A graphql form `raw.form` must be passed", (raw === null || raw === void 0 ? void 0 : (_raw$form = raw.form) === null || _raw$form === void 0 ? void 0 : _raw$form.__typename) === "Form"));
(true && !(_raw$answers.every(answer => /Answer$/.test(answer.__typename))) && (0, _debug.assert)("A collection of graphql answers `raw.answers` must be passed", raw === null || raw === void 0 ? void 0 : (_raw$answers = raw.answers) === null || _raw$answers === void 0 ? void 0 : _raw$answers.every(answer => /Answer$/.test(answer.__typename))));

Bizarrely _raw$answers gets initialised to undefined and then .every is run on it in the ternary operator. No assignment to it happens before that.

image

StephanH90 commented 2 years ago

This was fixed by removing "Edge 18" from the build targets.