You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Surveys: an optional rating question with response-based branching throws "The response type must be an integer" when skipped #5278
A popover survey whose optional rating question uses response-based branching cannot be skipped. With no rating chosen, Submit stays enabled. Clicking it throws inside the click handler, and the survey neither advances nor sends a response:
Error: The response type must be an integer
The respondent sees nothing happen. They either pick a rating and submit again, or close the survey, and the response is lost.
Versions
posthog-js 1.428.3 (surveys.js from the assets CDN). Still identical in 1.438.7 and on main at 4f590b3.
Steps to reproduce
Create a popover survey with an optional rating question that branches on its answer, for example:
Show it, e.g. posthog.displaySurvey(id, { displayType: "popover", ignoreConditions: true }).
Click Submit without choosing a rating.
Expected: the survey moves on. An optional question was skipped, so the default next question applies, as it already does for an optional single-choice question with response-based branching. Actual:Error: The response type must be an integer is thrown from the click handler, and the survey stays on the question.
Cause
RatingQuestion: submitDisabled={isNull(rating) && !question.optional}, then onSubmit(rating). An optional rating submits null.
getNextSurveyStep: for a response_based rating it throws on any non-integer response, null included. The submit handler calls it before advancing, so the throw aborts the step.
Suggested fix
In getNextSurveyStep, treat an empty response (null/undefined) to an optional question as "no branch matched" and return the default next index instead of throwing. Keep the throw for genuinely malformed values. Alternatively, the survey editor could refuse to save the combination (optional + response-based branching on a rating question), but the SDK fix also covers surveys that already exist.
A minimal standalone reproduction (posthog-js only, array.full.js + displaySurvey against stubbed /api/surveys/) is available on request.
Conclusion: Confirmed browser-survey bug: an optional, response-branched rating submits null, but the branching helper rejects it before navigation. Confidence: 98% Suggested labels:feature/surveys, web, team/client-libraries, bug
Thanks for the precise reproduction and source references. This is confirmed in the current source: optional rating questions intentionally enable Submit with no selected value and submit null, while response-based rating branching currently throws for that value. The intended behavior is to treat an empty optional response as unmatched and continue to the default next question, while retaining validation for non-empty malformed rating values.
Investigation
RatingQuestion enables its submit button when question.optional is true and its unselected state is rating === null; clicking Submit calls onSubmit(rating) with that null value.
onNextButtonClick records the response and then calls getNextSurveyStep before it can update the current question or emit a survey event. Therefore the thrown branching error aborts the reported submission flow.
For response-based rating branching, getNextSurveyStep throws The response type must be an integer unless the response is an integer. It does not currently distinguish an intentionally skipped optional rating from malformed input.
Response-based single-choice questions already fall through to nextQuestionIndex when no response value matches, including an unselected optional response; this supports the requested default-navigation behavior.
Existing branching tests cover valid rating buckets and assert that non-numeric strings still throw, but do not cover a null response for an optional rating question.
recordSurveyAnswer deliberately records null responses, so the failure is navigation/branching-specific rather than an inability to represent a skipped answer.
Reason: The defect is isolated to one validation path and does not require a public API or survey-schema change. The existing component behavior establishes that null is the intentional skipped value for optional ratings.
Suggested approach: In getNextSurveyStep, before rating integer validation, return nextQuestionIndex when a response-based rating question is optional and its response is null (and, if runtime callers may pass it, undefined). Add a focused regression test using an optional response-based rating followed by another question, asserting that a null response returns the default next index. Keep existing throws for non-empty invalid values such as strings and out-of-range integers.
Activity
github-actions commentedon Oct 11, 2026
AI triage for #5278
Conclusion: Confirmed browser-survey bug: an optional, response-branched rating submits null, but the branching helper rejects it before navigation.
Confidence: 98%
Suggested labels:
feature/surveys,web,team/client-libraries,bugThanks for the precise reproduction and source references. This is confirmed in the current source: optional rating questions intentionally enable Submit with no selected value and submit
null, while response-based rating branching currently throws for that value. The intended behavior is to treat an empty optional response as unmatched and continue to the default next question, while retaining validation for non-empty malformed rating values.Investigation
RatingQuestionenables its submit button whenquestion.optionalis true and its unselected state israting === null; clicking Submit callsonSubmit(rating)with that null value.onNextButtonClickrecords the response and then callsgetNextSurveyStepbefore it can update the current question or emit a survey event. Therefore the thrown branching error aborts the reported submission flow.getNextSurveyStepthrowsThe response type must be an integerunless the response is an integer. It does not currently distinguish an intentionally skipped optional rating from malformed input.nextQuestionIndexwhen no response value matches, including an unselected optional response; this supports the requested default-navigation behavior.recordSurveyAnswerdeliberately records null responses, so the failure is navigation/branching-specific rather than an inability to represent a skipped answer.Relevant files:
packages/browser/src/extensions/surveys/components/QuestionTypes.tsx,packages/browser/src/utils/survey-branching.ts,packages/browser/src/extensions/surveys.tsx,packages/browser/src/__tests__/surveys.test.ts,packages/browser/src/__tests__/extensions/surveys/question-types.test.tsx,packages/core/src/surveys/events.ts,packages/browser-common/src/types/surveys.tsFix assessment
getNextSurveyStep, before rating integer validation, returnnextQuestionIndexwhen a response-based rating question is optional and its response is null (and, if runtime callers may pass it, undefined). Add a focused regression test using an optional response-based rating followed by another question, asserting that a null response returns the default next index. Keep existing throws for non-empty invalid values such as strings and out-of-range integers.Draft PR: #5279
Pi session
The resumable JSONL pi session for this run was saved to a private gist: https://gist.github.com/marandaneto/4ad9502e6a20857d8b2e090d559ca518
Download it locally, then fork it into your own pi session:
Saved session:
call-1-1-2026-10-11T21-23-11-616Z_01a12cd9-2880-7c9c-9fc0-8b28440dfc68.jsonlClose proposal
None. No issue close action was taken.
Generated by posthog-watcher-action using pi.
Fix #5278: Surveys: an optional rating question with response-based b…
dustinbyrne commentedon Oct 12, 2026
Thanks for the issue @AndZp! This will be fixed with #5279
Fix #5278: Surveys: an optional rating question with response-based b…
fix: Surveys: an optional rating question with response-based branchi…
chore: sync main into capture-v1 (posthog-node 5.58.0-5.61.1) (#5508)