Skip to content

fix(gatsby-source-strapi): nested relation cache invalidation#524

Open
molund wants to merge 2 commits intogatsby-uc:mainfrom
molund:fix-nested-strapi-caching
Open

fix(gatsby-source-strapi): nested relation cache invalidation#524
molund wants to merge 2 commits intogatsby-uc:mainfrom
molund:fix-nested-strapi-caching

Conversation

@molund
Copy link

@molund molund commented Mar 10, 2026

Description

Gatsby's cache invalidation for gatsby-source-strapi only considered the top-level updatedAt/publishedAt fields on a Strapi entry. When a nested relation was updated in Strapi, the parent entry's top-level timestamps remained unchanged — causing Gatsby to treat the entry as unmodified and serve stale data.

Solution

Added a findLatestDates utility to clean-data.js that recursively traverses the entire cleaned entry — including all nested objects and arrays — and returns the maximum updatedAt and publishedAt values found anywhere in the document tree.

cleanData now overwrites the top-level updatedAt and publishedAt with these maximums before returning, ensuring that any change to any relation at any depth of nesting will correctly bust the cache.

Compatible with both Strapi v4 and v5 because findLatestDates operates on the output of cleanAttributes, not on the raw API response.

Related Issues

Fixes #523

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

⚠️ No Changeset found

Latest commit: bdb930d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@moonmeister
Copy link
Contributor

Thanks for the PR! I'll take a look next week likely or maybe @laurenskling will have time as he's the resident Strapi expert.

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.

bug(gatsby-source-strapi): cache is not invalidated when nested relations have newer updatedAt/publishedAt

2 participants