Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve nested relations in content blocks properly #903

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

edodusi
Copy link
Contributor

@edodusi edodusi commented Dec 19, 2024

Fix nested relations resolution in Storyblok SDK

Pull request type

Internal ref: #13985

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Other (please describe):

How to test this PR

  1. Create a story with nested relations (e.g., an event_slider with spots containing event_type relations)
  2. Request the story with resolve_relations including both direct and nested relations:
const response = await Storyblok.get("cdn/stories/your-story", {
  version: "draft",
  resolve_relations: [
    "event.event_type",
    "event_slider.spots"
  ]
});
  1. Verify that nested relations (like story.content.body[0].spots[0].content.event_type) are properly resolved to objects instead of remaining as UUIDs

What is the new behavior?

  • Fixed nested relations resolution by improving the field pattern matching in _insertRelations
  • Added support for resolving relations at any nesting level within the content tree
  • Added unit tests to verify proper resolution of nested relations
  • The fix ensures that all relations are properly resolved, regardless of their position in the content structure

Other information

This fix addresses an issue where nested relations (relations within component arrays or nested content) were not being properly resolved, remaining as UUIDs instead of being replaced with their corresponding objects. The solution improves the relation resolution logic to handle relations at any nesting level while maintaining backwards compatibility with existing functionality.

Copy link

pkg-pr-new bot commented Dec 20, 2024

Open in Stackblitz

npm i https://pkg.pr.new/storyblok-js-client@903

commit: 1cbb6cf

Copy link
Contributor

@roberto-butti roberto-butti left a comment

Choose a reason for hiding this comment

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

I tested with the original use case and is fine, now.
I tested also some different scenario like: nested relations and nested duplicated relations. So the applied changes covers more scenarios than the current version

@edodusi edodusi merged commit 1e1bbd9 into main Dec 23, 2024
6 checks passed
@edodusi edodusi deleted the fix/resolve-nested-relations branch December 23, 2024 11:18
Copy link

🎉 This PR is included in version 6.10.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants