@contentful/experiences-core 1.30.0-dev-20250128T1255-64f728a.0 → 1.30.0-dev-20250129T1011-3298201.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3640,6 +3640,33 @@ const removeCircularPatternReferences = (experienceEntry, _parentIds) => {
|
|
|
3640
3640
|
// @ts-expect-error - type of usedComponents doesn't yet allow a mixed list of both links and entries
|
|
3641
3641
|
experienceEntry.fields.usedComponents = newUsedComponents;
|
|
3642
3642
|
};
|
|
3643
|
+
/**
|
|
3644
|
+
* The CMA client will automatically replace links with entry references if they are available.
|
|
3645
|
+
* While we're not fetching the data sources, a self reference would be replaced as the entry is
|
|
3646
|
+
* fetched. Any circuar reference in the object breaks SSR where we have to stringify the JSON.
|
|
3647
|
+
* This would fail if the object contains circular references.
|
|
3648
|
+
*/
|
|
3649
|
+
const removeSelfReferencingDataSource = (experienceEntry) => {
|
|
3650
|
+
const dataSources = experienceEntry.fields.dataSource;
|
|
3651
|
+
const newDataSource = Object.entries(dataSources).reduce((acc, [key, linkOrEntry]) => {
|
|
3652
|
+
if ('fields' in linkOrEntry && linkOrEntry.sys.id === experienceEntry.sys.id) {
|
|
3653
|
+
const entry = linkOrEntry;
|
|
3654
|
+
acc[key] = {
|
|
3655
|
+
sys: {
|
|
3656
|
+
id: entry.sys.id,
|
|
3657
|
+
linkType: 'Entry',
|
|
3658
|
+
type: 'Link',
|
|
3659
|
+
},
|
|
3660
|
+
};
|
|
3661
|
+
}
|
|
3662
|
+
else {
|
|
3663
|
+
const link = linkOrEntry;
|
|
3664
|
+
acc[key] = link;
|
|
3665
|
+
}
|
|
3666
|
+
return acc;
|
|
3667
|
+
}, {});
|
|
3668
|
+
experienceEntry.fields.dataSource = newDataSource;
|
|
3669
|
+
};
|
|
3643
3670
|
|
|
3644
3671
|
const errorMessagesWhileFetching$1 = {
|
|
3645
3672
|
experience: 'Failed to fetch experience',
|
|
@@ -3671,6 +3698,7 @@ async function fetchBySlug({ client, experienceTypeId, slug, localeCode, isEdito
|
|
|
3671
3698
|
throw new Error(`No experience entry with slug: ${slug} exists`);
|
|
3672
3699
|
}
|
|
3673
3700
|
removeCircularPatternReferences(experienceEntry);
|
|
3701
|
+
removeSelfReferencingDataSource(experienceEntry);
|
|
3674
3702
|
try {
|
|
3675
3703
|
const { entries, assets } = await fetchReferencedEntities({
|
|
3676
3704
|
client,
|
|
@@ -3724,6 +3752,7 @@ async function fetchById({ client, experienceTypeId, id, localeCode, isEditorMod
|
|
|
3724
3752
|
throw new Error(`No experience entry with id: ${id} exists`);
|
|
3725
3753
|
}
|
|
3726
3754
|
removeCircularPatternReferences(experienceEntry);
|
|
3755
|
+
removeSelfReferencingDataSource(experienceEntry);
|
|
3727
3756
|
try {
|
|
3728
3757
|
const { entries, assets } = await fetchReferencedEntities({
|
|
3729
3758
|
client,
|