Use datocms astro components instead of own components#335
Use datocms astro components instead of own components#335JopMolenaar wants to merge 14 commits intomainfrom
Conversation
7c8b6f5 to
ad393eb
Compare
Deploying head-start with
|
| Latest commit: |
3a947f9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3fda8dfd.head-start.pages.dev |
| Branch Preview URL: | https://feat-use-datocms-astro-compo.head-start.pages.dev |
bae5999 to
38dc91a
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the project’s Structured Text and image rendering to the official @datocms/astro components, removing the custom StructuredText implementation and updating blocks/docs accordingly.
Changes:
- Replaced the custom StructuredText renderer with a new
src/components/Text/Text.astrowrapper around@datocms/astro/StructuredText, including node overrides and record/block mappings. - Updated the Image block to use
@datocms/astro’s Image component and adjusted GraphQL fragments/tests for the new data shape. - Removed the legacy
src/components/StructuredText/*implementation and updated usage/docs across blocks.
Reviewed changes
Copilot reviewed 33 out of 37 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/Text/Text.test.ts | Updates the tested component import for the new Text wrapper. |
| src/components/Text/Text.astro | New Structured Text wrapper using @datocms/astro/StructuredText with overrides/mappings. |
| src/components/Text/README.md | Documents new Text/StructuredText usage and override behavior. |
| src/components/Text/nodes/Paragraph.astro | Adds paragraph override with centered styling support. |
| src/components/Text/nodes/ItemLink.astro | Aligns item-link rendering with record-based props. |
| src/components/Text/nodes/Heading.astro | Keeps heading behavior while enforcing h2+ levels. |
| src/components/Text/nodes/Code.astro | Updates code rendering to a safer <pre><code> output. |
| src/components/Text/nodes/Block.astro | Adds block renderer to route structured-text blocks through ~/blocks/Blocks.astro. |
| src/components/StructuredText/StructuredText.d.ts | Removes legacy StructuredText typing helper. |
| src/components/StructuredText/StructuredText.astro | Removes legacy StructuredText component implementation. |
| src/components/StructuredText/README.md | Removes legacy StructuredText documentation. |
| src/components/StructuredText/Nodes/ThematicBreak.astro | Removes legacy node component. |
| src/components/StructuredText/Nodes/Span.astro | Removes legacy node component. |
| src/components/StructuredText/Nodes/Root.astro | Removes legacy node component. |
| src/components/StructuredText/Nodes/ListItem.astro | Removes legacy node component. |
| src/components/StructuredText/Nodes/List.astro | Removes legacy node component. |
| src/components/StructuredText/Nodes/Link.test.ts | Removes legacy Link node test. |
| src/components/StructuredText/Nodes/Link.astro | Removes legacy Link node component. |
| src/components/StructuredText/Nodes/InlineBlock.astro | Removes legacy inline block node component. |
| src/components/StructuredText/Nodes/Blockquote.astro | Removes legacy node component. |
| src/components/StructuredText/Node.astro | Removes legacy recursive node renderer. |
| src/components/LinkToRecord/LinkToRecord.astro | Extends record linking to support VariableRecord rendering. |
| src/blocks/TextImageBlock/TextImageBlock.astro | Switches to shared ~/components/Text/Text.astro. |
| src/blocks/TextBlock/TextBlock.astro | Switches to shared ~/components/Text/Text.astro. |
| src/blocks/TextBlock/Text.astro | Removes legacy shared TextBlock StructuredText adapter. |
| src/blocks/TextBlock/README.md | Updates docs to reflect the moved Text logic. |
| src/blocks/TextBlock/nodes/InlineItem.astro | Removes legacy inline item renderer (variable/link handling). |
| src/blocks/TextBlock/nodes/Heading.astro | Removes legacy heading override implementation. |
| src/blocks/ListBlock/ListBlockFragment.graphql | Adds links selection for list-item structured text. |
| src/blocks/ListBlock/ListBlock.astro | Switches to shared ~/components/Text/Text.astro. |
| src/blocks/ImageBlock/README.md | Updates docs to reference DatoCMS Astro image handling. |
| src/blocks/ImageBlock/ImageBlock.test.ts | Updates expectations for the new image output/styling behavior. |
| src/blocks/ImageBlock/ImageBlock.fragment.graphql | Adds srcSet to the image responsive payload. |
| src/blocks/ImageBlock/Image.client.ts | Removes custom element behavior previously used for load handling. |
| src/blocks/ImageBlock/Image.astro | Migrates image rendering to @datocms/astro Image and updates fallback styling. |
| package.json | Adds @datocms/astro dependency. |
| package-lock.json | Locks @datocms/astro and transitive dependencies. |
Comments suppressed due to low confidence (1)
src/components/Text/Text.test.ts:6
Text.astroexpects adataprop, but this test renders the component without providing any props. That will passundefinedinto@datocms/astro’sStructuredTextand is likely to throw at runtime, causing the test to fail. Pass a minimal valid Structured Text value inrenderToFragmentoptions (or updateText.astroto safely handle missing/nulldata).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const astroImageData = { | ||
| src: image.url, | ||
| srcSet: image.responsiveImage?.srcSet ?? null, | ||
| title: image.title, | ||
| width: image.width, | ||
| height: image.height, | ||
| alt: altText, | ||
| base64: image.responsiveImage?.base64 || '', | ||
| }; |
There was a problem hiding this comment.
AstroImage is fed srcSet from image.responsiveImage?.srcSet, but some GraphQL fragments in the repo still fetch responsiveImage without srcSet (e.g. TextImageBlock.fragment.graphql currently selects aspectRatio + base64 only). In those cases image.responsiveImage will be truthy, you’ll take the bitmap branch, and srcSet becomes null, which may break the DatoCMS image component. Ensure all fragments that supply image.responsiveImage also include the fields required by @datocms/astro (at least srcSet), or change the condition to only use AstroImage when the required fields are present.
There was a problem hiding this comment.
@milailijevic Yes, TextImageBlock.fragment.graphql is now also fetching srcSet, and if I search on responsiveImage, all of them have srcSet in it.
But even when srcSet is missing, AstroImage has its own buildSrcSet function, so it won't break anything.
| const locale = getLocale() as SiteLocale; | ||
| const href = getHref({ locale, record }); | ||
| const href = getHref({ locale, record: record as RecordRoute }); | ||
| --- |
There was a problem hiding this comment.
href is computed for every record via record as RecordRoute, even when the record is a VariableRecord (where href isn’t used) and despite getHref not accepting VariableRecord in its type. Consider computing href only in the non-FileRecord/non-VariableRecord branch (or extending RecordRoute/getHref to include VariableRecord) to avoid the unsafe cast and unnecessary work.
a3c1884 to
025863a
Compare
…ify translation string
025863a to
3223e9e
Compare
| @@ -1 +1 @@ | |||
| fragment ImageBlock on ImageBlockRecord { | |||
There was a problem hiding this comment.
maybe using imgixParams here to limit the full size of it and set the q to 80 as we previously had
fragment ImageBlock on ImageBlockRecord {
id
image {
responsiveImage( imgixParams: { auto: [format, compress], q: 80, fit: max, w: 1200} ) {
srcSet
src
base64
alt
title
width
height
}
}
}
and then just use const astroImageData = image.responsiveImage ?? null; in Image.astro.
This is just an idea, it scales the image with dpr as in this example but limiting the biggest one is the issue here.
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?auto=format%2Ccompress&dpr=0.25&fit=max&q=80&w=1200
The maxW param doesn't work without the fit=crop
having imgixParams: { auto: [format, compress], q: 80, fit: max, w: 1200} in the query works fine, but the params stay the same except from the dpr
| } | ||
| value | ||
| } | ||
| image { |
There was a problem hiding this comment.
should follow the same structure as in ImageBlock.fragment.graphql if you change it
| export type Props = Omit<HTMLAttributes<'a'>, 'href'> & { | ||
| openInNewTab?: boolean; | ||
| record: RecordRoute; | ||
| record: RecordRoute | VariableRecord; |
There was a problem hiding this comment.
Rebase to main, the VariableRecord type is not used here anymore
Changes
Use datocms astro components instead of own components
Associated issue
Resolves #333
How to test
Structured text:
Image component:
Checklist