0

I am currently using surveyjs within a react app. I have a custom function that returns an uuid value and I invoke that function using an expression in the surveyjs JSON. Now, I have observed the following.

  1. This uuid() has no parameter input, yet whenever I select any value from any other dropdown of any other field in the form that has no dependency with the uuid expression field, then also the uuid value of the expression gets updated - unnecessarily and this also causes a re-render.

  2. If I have a function with a parameter input, this parameter input comes from a particular field of the survey. Now even if I alter another field that is not related to the parameter input of this expression custom function, then also expression gets re-evaluated and the function is re-invoked. This also causes an unnecessary re-render.

  3. Considering the obs#2, if I put the mentioned function with single param input within an iif() statement, such that the function should only be invoked if the condition is true, then also the expression containing the function gets evaluated even though the condition is false. This is preventing me from restricting a custom function call via iif statement.

Consider this example for understanding the scenario better.

{
   "type": "expression",
   "name": "audit_id",
   "expression": "uuid()"
},
{
   "type": "dropdown",
   "name": "audit_type",
   "choices": ["audit-type1", "audit-type2"]
},
{
   "type": "dropdown",
   "name": "model",
   "choices": ["model1", "model2"]
},
{
   "type": "expression",
   "name": "service",
   "expression": "iif({enable_model} == true, findServiceByModel({model})), 'null'"
},
{
   "type": "boolean",
   "name": "enable_model",
   "valueTrue": "true",
   "valueFalse": "false"
}

Note: findServiceByModel() is already registered in a FunctionFactory instance and async in nature.

In this example

  1. audit_id get re-evaluated each time I change audit_type dropdown value.
  2. findServiceByModel() will get invoked even if I change audit_type which is completely independant.
  3. findServiceByModel() will get invoked even if enable_model is set to false.

Please let me know how the above concerns can be addressed in surveyjs.

Thanks,

Stacktrace evidence:

App.js:182  No parameters received
overrideMethod @ hook.js:608
findOCRService @ App.js:182
FunctionFactory.run @ functionsfactory.ts:60
FunctionOperand.evaluateCore @ expressions.ts:382
FunctionOperand.evaluate @ expressions.ts:367
ExpressionExecutorRunner.runAsyncItemCore @ conditions.ts:86
ExpressionExecutorRunner.runAsyncItem @ conditions.ts:81
(anonymous) @ conditions.ts:79
ExpressionExecutorRunner.runAsyncItem @ conditions.ts:79
ExpressionExecutorRunner.run @ conditions.ts:64
ExpressionExecutor.run @ conditions.ts:173
ExpressionRunnerBase.runCore @ conditions.ts:225
ExpressionRunner.run @ conditions.ts:248
QuestionExpressionModel.runCondition @ question_expression.ts:77
PanelModelBase.runCondition @ panel.ts:1934
QuestionCompositeModel.runCondition @ question_custom.ts:1206
PanelModelBase.runCondition @ panel.ts:1934
PanelModelBase.runCondition @ panel.ts:1934
QuestionPanelDynamicModel.runPanelsCondition @ question_paneldynamic.ts:1890
QuestionPanelDynamicModel.runCondition @ question_paneldynamic.ts:1856
PanelModelBase.runCondition @ panel.ts:1934
SurveyModel.runConditionsCore @ survey.ts:6124
SurveyModel.runConditions @ survey.ts:6070
SurveyModel.runConditionOnValueChanged @ survey.ts:6105
SurveyModel.checkTriggersAndRunConditions @ survey.ts:6032
SurveyModel.updateOnSetValue @ survey.ts:6720
SurveyModel.setValue @ survey.ts:6695
Question.setValueCore @ question.ts:2407
QuestionPanelDynamicModel.setValueCore @ question_paneldynamic.ts:910
Question.setNewValueInData @ question.ts:2397
Question.setNewValue @ question.ts:2354
set @ question.ts:1629
QuestionPanelDynamicModel.setPanelItemData @ question_paneldynamic.ts:2284
QuestionPanelDynamicItem.setValue @ question_paneldynamic.ts:158
Question.setValueCore @ question.ts:2407
QuestionSelectBase.setValueCore @ question_baseselect.ts:672
Question.setNewValueInData @ question.ts:2397
Question.setNewValue @ question.ts:2354
QuestionSelectBase.setNewValue @ question_baseselect.ts:687
set @ question.ts:1629
_onSelectionChanged @ dropdownListModel.ts:221
ListModel._this.onItemClick @ list.ts:211
onClick @ list-item.tsx:53

1 Answer 1

0

Unfortunately right now all expressions in SurveyJS are being re-evaluated on every chanage in any survey question.

Sign up to request clarification or add additional context in comments.

3 Comments

But this is ultimately killing the performance and the UI thread is lagging due to unnecessary evaluations. Even using 'async' functions doesn't help out. Can you suggest a temporary hack or walkaround to avoid this?
And should I log this issue in surveyjs' Github repo as well?
Why wouldn't? The github.com/surveyjs/survey-library/issues is a right place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.