surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.12k stars 802 forks source link

onPartialSend gets removed in React strict mode #7924

Open JakeCoxon opened 7 months ago

JakeCoxon commented 7 months ago

Are you requesting a feature, reporting a bug or asking a question?

Reporting a bug

What is the current behavior?

When Survey is remounted it modifies the SurveyModel and removes all onPartialSend callbacks

https://github.com/surveyjs/survey-library/blob/ddb86f54443a34ad4a369517d7f2f16e50e1fe4e/src/react/reactSurvey.tsx#L74C1-L74C41

When using React.StrictMode the SurveyComponent gets remounted automatically. But this will happen in other unmounting cases

What is the expected behavior?

I understand that line is supposed to remove the callback added elsewhere in the file, I would expect my existing callbacks to be remain.

How would you reproduce the current behavior (if this is a bug)?

Load the page below and you will see two renders and the useEffect will say the function is no longer in the event listener

Render
Render
hasFunc? true
hasFunc? false

And if you try pressing the next button it does not call the callback.

Provide the test code and the tested page URL (if applicable)

https://codesandbox.io/p/sandbox/determined-moon-6fljq5?file=%2Fsrc%2FSurveyComponent.jsx%3A8%2C1

Specify your

JaneSjs commented 3 months ago

Hello @JakeCoxon, I put debugger within the onPartialSend function and confirmed that this function is invoked when the navigating to the next survey page. Please let me know whether you have any difficulties using the onPartialSend function. For the record: we may also recommend sending survey responses within the current page changed callback function. Please refer to the following demo: Continue an Incomplete Survey.