Skip to content

Commit

Permalink
fix(schema-extract): handle title sometimes being a React node (#2002)
Browse files Browse the repository at this point in the history
* chore: reproduce error

* fix(schema-extract): handle `title` sometimes being a React node

* chore: bump turbo
  • Loading branch information
stipsan authored Oct 21, 2024
1 parent e1ab108 commit 3dad7aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/@repo/sanity-schema/src/page-builder-demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const productType = defineType({
defineField({
type: 'array',
name: 'media',
title: 'Media',
// @ts-expect-error this is actually allowed at runtime
title: <>Media</>,
// title: 'Media',
of: [
{
type: 'image',
Expand Down
10 changes: 5 additions & 5 deletions packages/presentation/src/overlays/schema/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function extractSchema(workspace: Workspace, theme: ThemeContextValue): S
return {
type: 'document',
name: schemaType.name,
title: schemaType.title,
title: typeof schemaType.title === 'string' ? schemaType.title : undefined,
icon: extractIcon(schemaType),
fields: {
...documentDefaultFields(schemaType.name),
Expand Down Expand Up @@ -287,7 +287,7 @@ export function extractSchema(workspace: Workspace, theme: ThemeContextValue): S

return {
name: schemaType.name,
title: schemaType.title,
title: typeof schemaType.title === 'string' ? schemaType.title : undefined,
type: 'type',
value,
}
Expand All @@ -307,7 +307,7 @@ export function extractSchema(workspace: Workspace, theme: ThemeContextValue): S
fields[field.name] = {
type: 'objectField',
name: field.name,
title: field.type.title,
title: typeof field.type.title === 'string' ? field.type.title : undefined,
value,
optional: isFieldRequired(field) === false,
}
Expand Down Expand Up @@ -423,7 +423,7 @@ export function extractSchema(workspace: Workspace, theme: ThemeContextValue): S
type: 'unionOption',
icon: extractIcon(item),
name: item.name,
title: item.title,
title: typeof item.title === 'string' ? item.title : undefined,
value: field,
} satisfies SchemaUnionOption
if (field.type === 'inline') {
Expand Down Expand Up @@ -464,7 +464,7 @@ export function extractSchema(workspace: Workspace, theme: ThemeContextValue): S
of: {
type: 'arrayItem',
name,
title,
title: typeof title === 'string' ? title : undefined,
value,
},
}
Expand Down

0 comments on commit 3dad7aa

Please sign in to comment.