surveyjs / surveyjs_react_quickstart

SurveyJS + React Quickstart Template
http://surveyjs.io
140 stars 78 forks source link

Error with SurveyCreator component in ReactJS #19

Closed Garwin4j closed 4 years ago

Garwin4j commented 4 years ago

Hello, I get this error when I try to use the SurveyCreator component in ReactJS: (I copied the SurveyCreator file directly).

React: 16.12.0 Typescript: 3.8.2 SurveyCreator: 1.7.9

reactSurvey.tsx:366 Uncaught TypeError: Cannot set property 'renderCallback' of undefined at Survey.setSurveyEvents (reactSurvey.tsx:366) at Survey.createSurvey (reactSurvey.tsx:329) at new Survey (reactSurvey.tsx:34) at constructClassInstance (react-dom.development.js:12880) at updateClassComponent (react-dom.development.js:17100) at beginWork (react-dom.development.js:18620) at HTMLUnknownElement.callCallback (react-dom.development.js:188) at HTMLUnknownElement.wrapped (build.umd.js:2425) at Object.invokeGuardedCallbackDev (react-dom.development.js:237) at invokeGuardedCallback (react-dom.development.js:292) at beginWork$1 (react-dom.development.js:23203) at performUnitOfWork (react-dom.development.js:22154) at workLoopSync (react-dom.development.js:22130) at performSyncWorkOnRoot (react-dom.development.js:21756) at react-dom.development.js:11089 at unstable_runWithPriority (scheduler.development.js:653) at runWithPriority$1 (react-dom.development.js:11039) at flushSyncCallbackQueueImpl (react-dom.development.js:11084) at flushSyncCallbackQueue (react-dom.development.js:11072) at discreteUpdates$1 (react-dom.development.js:21893) at discreteUpdates (react-dom.development.js:806) at dispatchDiscreteEvent (react-dom.development.js:4168)

tsv2013 commented 4 years ago

I've just cloned this repo, installed npm paskages and started app via the "npm start" command. The applications works ok for me. I've got working SurveyJS Creator and no errors in console. Can you provide us with a live sample and/or steps to reproduce the issue?

Garwin4j commented 4 years ago

Hi @tsv2013, thank for the reply.

I have create a project that uses react and typescript and trying to use the library, the repository has that : https://github.com/Garwin4j/surveyjs_error_example.

In this repo I get these errors:

Uncaught TypeError: this.survey.doAfterRenderSurvey is not a function at Survey.componentDidMount (survey.react.js:25777) at commitLifeCycles (react-dom.development.js:18071) at commitAllLifeCycles (react-dom.development.js:19630) at HTMLUnknownElement.callCallback (react-dom.development.js:147) at Object.invokeGuardedCallbackDev (react-dom.development.js:196) at invokeGuardedCallback (react-dom.development.js:250) at commitRoot (react-dom.development.js:19854) at react-dom.development.js:21402 at Object.unstable_runWithPriority (scheduler.development.js:255) at completeRoot (react-dom.development.js:21401) at performWorkOnRoot (react-dom.development.js:21324) at performWork (react-dom.development.js:21229) at performSyncWork (react-dom.development.js:21203) at requestWork (react-dom.development.js:21058) at scheduleWork (react-dom.development.js:20871) at scheduleRootUpdate (react-dom.development.js:21566) at updateContainerAtExpirationTime (react-dom.development.js:21592) at updateContainer (react-dom.development.js:21660) at ReactRoot.push../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:21973) at react-dom.development.js:22125 at unbatchedUpdates (react-dom.development.js:21448) at legacyRenderSubtreeIntoContainer (react-dom.development.js:22121) at render (react-dom.development.js:22196) at Module../src/index.tsx (index.tsx:9) at webpack_require__ (bootstrap:785) at fn (bootstrap:150) at Object.0 (survey_json.js:1) at webpack_require__ (bootstrap:785) at checkDeferredModules (bootstrap:45) at Array.webpackJsonpCallback [as push] (bootstrap:32) at main.chunk.js:1 index.js:1472 The above error occurred in the component: in Survey (at SurveyCreator.tsx:55) in div (at SurveyCreator.tsx:53) in SurveyPage (at src/index.tsx:5) in App (at src/index.tsx:9)

Consider adding an error boundary to your tree to customize error handling behavior. Visit https://fb.me/react-error-boundaries to learn more about error boundaries. console. @ index.js:1472 react-dom.development.js:21289 Uncaught TypeError: this.survey.doAfterRenderSurvey is not a function at Survey.componentDidMount (survey.react.js:25777) at commitLifeCycles (react-dom.development.js:18071) at commitAllLifeCycles (react-dom.development.js:19630) at HTMLUnknownElement.callCallback (react-dom.development.js:147) at Object.invokeGuardedCallbackDev (react-dom.development.js:196) at invokeGuardedCallback (react-dom.development.js:250) at commitRoot (react-dom.development.js:19854) at react-dom.development.js:21402 at Object.unstable_runWithPriority (scheduler.development.js:255) at completeRoot (react-dom.development.js:21401) at performWorkOnRoot (react-dom.development.js:21324) at performWork (react-dom.development.js:21229) at performSyncWork (react-dom.development.js:21203) at requestWork (react-dom.development.js:21058) at scheduleWork (react-dom.development.js:20871) at scheduleRootUpdate (react-dom.development.js:21566) at updateContainerAtExpirationTime (react-dom.development.js:21592) at updateContainer (react-dom.development.js:21660) at ReactRoot.push../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:21973) at react-dom.development.js:22125 at unbatchedUpdates (react-dom.development.js:21448) at legacyRenderSubtreeIntoContainer (react-dom.development.js:22121) at render (react-dom.development.js:22196) at Module../src/index.tsx (index.tsx:9) at webpack_require__ (bootstrap:785) at fn (bootstrap:150) at Object.0 (survey_json.js:1) at webpack_require__ (bootstrap:785) at checkDeferredModules (bootstrap:45) at Array.webpackJsonpCallback [as push] (bootstrap:32) at main.chunk.js:1

index.js:1472 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. in SurveyQuestion (created by SurveyRow) in div (created by SurveyRow) in SurveyRow (created by SurveyPage) in div (created by SurveyPage) in SurveyPage (created by Survey) in div (created by Survey) in div (created by Survey) in form (created by Survey) in div (created by Survey) in Survey (at SurveyCreator.tsx:55) in div (at SurveyCreator.tsx:53) in SurveyPage (at src/index.tsx:5) in App (at src/index.tsx:9)

tsv2013 commented 4 years ago

Model in a react app should be created as

var model = new Survey.Model(json);

It was impossible because of the "Model" name is not mentioned in typings.

As a workaround this can be used:

var model = new Survey["Model"](json);

I've fixed the https://github.com/surveyjs/survey-library/issues/2205. Fix will be available in 1.7.11

Garwin4j commented 4 years ago

Oh, so SurveyModel is not the same thing as Model?

On Thu, Jun 4, 2020, 6:50 AM tsv2013 notifications@github.com wrote:

Model in a react app should be created as

var model = new Survey.Model(json);

It was impossible because of the "Model" name is not mentioned in typings.

As a workaround this can be used:

var model = new Survey"Model";

I've fixed the surveyjs/survey-library#2205 https://github.com/surveyjs/survey-library/issues/2205. Fix will be available in 1.7.11

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/surveyjs/surveyjs_react_quickstart/issues/19#issuecomment-638799340, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAENQW7RSM5STGTWVGCEKKDRU6DATANCNFSM4NRBC7WA .

tsv2013 commented 4 years ago

Yes, the SurveyModel is a core platform-indepenedent object and doesn't have the doAfterRenderSurvey method.

Garwin4j commented 4 years ago

Hi @tsv2013, So when I make the change recommended it no longer has the "doAfterRenderSurvey" error, but now it goes back to the "renderCallback" error. Is there anything else I might be doing?

Garwin4j commented 4 years ago

Hey @tsv2013, scratch that, the error seems to be gone now. Thank you very much.