Skip to content

Fix TutorialLayout crash for tutorials without optional fields#1142

Open
hxrshxz wants to merge 3 commits intoprocessing:mainfrom
hxrshxz:fix/tutorial-optional-fields-validation
Open

Fix TutorialLayout crash for tutorials without optional fields#1142
hxrshxz wants to merge 3 commits intoprocessing:mainfrom
hxrshxz:fix/tutorial-optional-fields-validation

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Feb 5, 2026

Resolves #1006

The TutorialLayout component crashes when a tutorial doesn't have featuredImage or authors in its frontmatter because it tries to call .src and .join() on undefined values.

These fields are marked optional in the schema but are actually required for the site to function. As discussed in the issue, I went with a .refine() approach so that:

  • During npm run dev, the validation is skipped (via import.meta.env.DEV) so you can work on tutorials without filling in every field upfront
  • During npm run build / npm run check, it enforces that authors, featuredImage, featuredImageAlt, and description are present — so incomplete tutorials can't make it to production

Also added optional chaining in TutorialLayout.astro on the two lines that were actually crashing, so the dev server doesn't blow up when those fields are missing.

Copilot AI review requested due to automatic review settings February 5, 2026 16:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes crashes in TutorialLayout when tutorials lack optional authors and featuredImage fields by adding optional chaining, and adds build-time validation to ensure production builds require these fields plus description and featuredImageAlt. The solution allows flexible development iterations while enforcing completeness for production deployments.

Changes:

  • Added .refine() validation in tutorial schema that skips validation in dev mode but enforces required fields (authors, featuredImage, featuredImageAlt, description) in production builds
  • Added optional chaining (?.) in TutorialLayout for authors and featuredImage field accesses to prevent runtime crashes during development

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/content/tutorials/config.ts Added production-only validation using .refine() to enforce required fields while keeping them optional in the type system for dev flexibility
src/layouts/TutorialLayout.astro Added optional chaining to prevent TypeError crashes when accessing authors and featuredImage properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hxrshxz hxrshxz marked this pull request as draft February 5, 2026 16:45
@hxrshxz hxrshxz force-pushed the fix/tutorial-optional-fields-validation branch from 497c286 to d3a3d9c Compare February 5, 2026 16:46
@hxrshxz hxrshxz force-pushed the fix/tutorial-optional-fields-validation branch from d3a3d9c to 67f3734 Compare February 5, 2026 16:48
@hxrshxz hxrshxz marked this pull request as ready for review February 5, 2026 16:52
Copy link
Member

@ksen0 ksen0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hxrshxz , a couple of minor tweaks please.

@hxrshxz
Copy link
Contributor Author

hxrshxz commented Feb 6, 2026

I have addressed your feedbacks , thank you

@hxrshxz hxrshxz requested a review from ksen0 February 6, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TutorialLayout crashes rendering tutorials without optional featuredImage and authors fields

2 participants