fix: ensure survey.endings is always an array to prevent TypeError

Fixes FORMBRICKS-JE

- Added default empty array for survey.endings in transformPrismaSurvey
- Added defensive checks in progress-bar component and utils
- Fixed migration to handle null endings
- Prevents 'TypeError: e is not iterable' when survey.endings is null/undefined
This commit is contained in:
Cursor Agent
2026-02-11 13:47:56 +00:00
parent fad55e3486
commit 30a9dbd1a8
4 changed files with 4 additions and 3 deletions

View File

@@ -30,6 +30,7 @@ export const transformPrismaSurvey = <T extends TSurvey | TJsEnvironmentStateSur
displayPercentage: Number(surveyPrisma.displayPercentage) || null,
segment,
customHeadScriptsMode: surveyPrisma.customHeadScriptsMode,
endings: surveyPrisma.endings || [],
} as T;
return transformedSurvey;

View File

@@ -62,7 +62,7 @@ export const removeEmptyImageAndVideoUrlsFromElements: MigrationScript = {
delete cleanedWelcomeCard.videoUrl;
}
const cleanedEndings = survey.endings.map((ending) => {
const cleanedEndings = (survey.endings || []).map((ending) => {
const cleanedEnding = { ...ending };
if (cleanedEnding.imageUrl === "") {
delete cleanedEnding.imageUrl;

View File

@@ -13,7 +13,7 @@ export function ProgressBar({ survey, blockId }: ProgressBarProps) {
[survey.blocks, blockId]
);
const endingCardIds = useMemo(() => survey.endings.map((ending) => ending.id), [survey.endings]);
const endingCardIds = useMemo(() => (survey.endings || []).map((ending) => ending.id), [survey.endings]);
const calculateProgress = useCallback(
(blockIndex: number) => {

View File

@@ -87,7 +87,7 @@ export const calculateElementIdx = (
const currentQuestion = questions[currentQustionIdx];
const middleIdx = Math.floor(totalCards / 2);
const possibleNextBlockIds = getPossibleNextBlocks(survey.blocks, currentQuestion);
const endingCardIds = survey.endings.map((ending) => ending.id);
const endingCardIds = (survey.endings || []).map((ending) => ending.id);
// Convert block IDs to element IDs (get first element of each block)
const possibleNextQuestionIds = possibleNextBlockIds