From cd4c33a3f226c8a652f21915f5b97449e16dac09 Mon Sep 17 00:00:00 2001 From: Valknar XXX Date: Wed, 29 Oct 2025 04:33:52 +0100 Subject: [PATCH] fix: safely handle empty/null models array in getVideoBySlug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added null/undefined checks before mapping models array - Filter out invalid entries in models junction table data - Default to empty array if models is not an array - Prevents "Cannot read properties of undefined" errors on video pages This fix ensures the video detail page works even when model associations are missing or malformed in the database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/frontend/src/lib/services.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/lib/services.ts b/packages/frontend/src/lib/services.ts index 8eb736f..57d7477 100644 --- a/packages/frontend/src/lib/services.ts +++ b/packages/frontend/src/lib/services.ts @@ -266,7 +266,14 @@ export async function getVideoBySlug( if (videos.length === 0) { throw new Error("Video not found"); } - videos[0].models = videos[0].models.map((u) => u.directus_users_id!); + // Handle models array - filter out null/undefined and map to user objects + if (Array.isArray(videos[0].models)) { + videos[0].models = videos[0].models + .filter((u) => u && u.directus_users_id) + .map((u) => u.directus_users_id!); + } else { + videos[0].models = []; + } return videos[0]; });