Closed spacebaboon closed 7 years ago
Having the same error Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of 'Form'
0.41.0
Works
0.41.1
Doesn't
With exactly the same code
import commonCustomWidgets from 'common/custom-form-widgets';
import commonCustomFields from 'common/custom-form-fields';
import styles from './styles.css';
import React from 'react';
import Form from 'react-jsonschema-form';
const MadForm = props => {
const {
showErrorList = false,
hideSubmit = true,
children,
widgets = {},
fields = {},
...other
} = props;
return (
<div className={ styles.container }>
<Form
showErrorList={ showErrorList }
widgets={{ ...commonCustomWidgets, ...widgets }}
fields={{ ...commonCustomFields, ...fields }}
{ ...other }
>
{ children }
{ hideSubmit && <button type='submit' hidden>Save</button> }
</Form>
</div>
);
};
Props differs between components so it's not always the same, but never works, switching versions works well. Hope it helps!
We have very limited time to investigate this specific error with mocha. Could you please help us investigating and reducing the source of the error to its very minimal bit? Thanks for your understanding.
Sure, although I'm not sure I understand exactly what you need.
If it helps, I've only ever seen this error when I've made a mistake with import statements and used
import blah from 'blah'
instead of
import {blah} from 'blah'
so I think it must have come from a change in imports or exports involving Form.js that went into the 0.41.2 release.
this is still broken in v 0.42.0.
Sure, although I'm not sure I understand exactly what you need.
A reproducible test case.
If it helps, I've only ever seen this error when I've made a mistake with import statements
Wait, wouldn't that mean that the error is normal and expected?
Is the test in my original bug report not reproducible? Sorry if I'm missing something.
I meant that I've seen this error message when I've made a mistake in the past with imports from my code, so perhaps that's the also source of this bug in RJSF.
Yeah, my code isn't runnable, as I haven't included all my files. Let me see if I can give you a full example...
Well that was a fun half day! For some as yet unknown and utterly baffling reason, the presence of another test file, with which I can find no connection to RJSF causes something to happen which breaks the tests involving RJSF v0.41.2 and above. It will probably be something to do with the test environment needing to be cleaned up.
There was never a problem running our code with v0.41.2 or v0.42.0 in a browser, it was only test failures. I still need to find out why it's doing it, and I'll update this if I find anything related to RJSF, but I'm happy to close the bug.
I don't know if @goncy can also verify this, and if his problem is also test-related. Could you please try deleting other tests and just running the one where you found the error, and seeing if that fixes it?
I've failed to put together a cut-down reproducable test case which will show the error, and I'm not allowed to share all our code, and unfortunately I don't have any more time to spend on this right now.
I have narrowed it down to one class under test, which imports and uses SchemaField for some custom behaviour. Even if the class under test doesn't use the imported SchemaField, the presence of the import alone is enough. This somehow causes another test to fail with the error in the stacktrace I originally posted. This second test tests a class which imports and uses Form for custom behaviour. Both tests will pass if the other is deleted, so I guess the Mocha framework has both imported simultaneously, and this may be causing the problem. The failure also happens when ObjectField or StringField are imported, even if not used. Importing any of the other fields in the directory does not cause the error. There are no other error messages shown during the test run, only the stack trace I posted. This error is thrown during the test set up, before any individual test case has run. I have tried explicitly cleaning the jsdom environment between tests, this has no effect. The error happens in the second from top line in the stack trace, in instantiateReactComponent, as the element.type for Form is undefined, and it needs to be a string or function. The failure only started happening with v0.41.2.
Thanks for your investigation around this. Unfortunately, without a reproducible test case I'm gonna have to close the issue. Anyone feel free to reopen if that still happens and we can identify where does that come from precisely.
Prerequisites
Description
The following error is thrown in unit tests of a custom component wrapping RJSF after upgrading from 0.41.1 to 0.41.2:
These errors go away after downgrading again.
Steps to Reproduce
I have a custom form component which encapsulates some logic and presentation in order to present the form as we need it.
my tests use Enzyme's mount, and this set up file for js-dom
example test
Version
These are all my dependencies