fix: #1887, dataloader rich text population infinite loop
This commit is contained in:
@@ -31,16 +31,16 @@ export const populate = async ({
|
|||||||
}): Promise<void> => {
|
}): Promise<void> => {
|
||||||
const dataRef = data as Record<string, unknown>;
|
const dataRef = data as Record<string, unknown>;
|
||||||
|
|
||||||
const doc = await req.payload.findByID({
|
const doc = await req.payloadDataLoader.load(JSON.stringify([
|
||||||
req,
|
collection.config.slug,
|
||||||
collection: collection.config.slug,
|
|
||||||
id,
|
id,
|
||||||
currentDepth: currentDepth + 1,
|
|
||||||
overrideAccess: typeof overrideAccess === 'undefined' ? false : overrideAccess,
|
|
||||||
disableErrors: true,
|
|
||||||
depth,
|
depth,
|
||||||
|
currentDepth + 1,
|
||||||
|
req.locale,
|
||||||
|
req.fallbackLocale,
|
||||||
|
typeof overrideAccess === 'undefined' ? false : overrideAccess,
|
||||||
showHiddenFields,
|
showHiddenFields,
|
||||||
});
|
]));
|
||||||
|
|
||||||
if (doc) {
|
if (doc) {
|
||||||
dataRef[key] = doc;
|
dataRef[key] = doc;
|
||||||
|
|||||||
@@ -24,6 +24,42 @@ export default buildConfig({
|
|||||||
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
slug: 'relation-a',
|
||||||
|
labels: {
|
||||||
|
singular: 'Relation A',
|
||||||
|
plural: 'Relation As',
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'relationship',
|
||||||
|
type: 'relationship',
|
||||||
|
relationTo: 'relation-b',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'richText',
|
||||||
|
type: 'richText',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
slug: 'relation-b',
|
||||||
|
labels: {
|
||||||
|
singular: 'Relation B',
|
||||||
|
plural: 'Relation Bs',
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'relationship',
|
||||||
|
type: 'relationship',
|
||||||
|
relationTo: 'relation-a',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'richText',
|
||||||
|
type: 'richText',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
onInit: async (payload) => {
|
onInit: async (payload) => {
|
||||||
const user = await payload.create({
|
const user = await payload.create({
|
||||||
|
|||||||
@@ -49,5 +49,88 @@ describe('dataloader', () => {
|
|||||||
const { docs } = response.Posts;
|
const { docs } = response.Posts;
|
||||||
expect(docs[0].title).toStrictEqual(postDoc.title);
|
expect(docs[0].title).toStrictEqual(postDoc.title);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should avoid infinite loops', async () => {
|
||||||
|
const relationA = await payload.create({
|
||||||
|
collection: 'relation-a',
|
||||||
|
data: {
|
||||||
|
richText: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
text: 'relation a',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const relationB = await payload.create({
|
||||||
|
collection: 'relation-b',
|
||||||
|
data: {
|
||||||
|
relationship: relationA.id,
|
||||||
|
richText: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
text: 'relation b',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(relationA.id).toBeDefined();
|
||||||
|
expect(relationB.id).toBeDefined();
|
||||||
|
|
||||||
|
await payload.update({
|
||||||
|
collection: 'relation-a',
|
||||||
|
id: relationA.id,
|
||||||
|
data: {
|
||||||
|
relationship: relationB.id,
|
||||||
|
richText: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
text: 'relation a',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
text: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
type: 'relationship',
|
||||||
|
value: {
|
||||||
|
id: relationB.id,
|
||||||
|
},
|
||||||
|
relationTo: 'relation-b',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const relationANoDepth = await payload.findByID({
|
||||||
|
collection: 'relation-a',
|
||||||
|
id: relationA.id,
|
||||||
|
depth: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(relationANoDepth.relationship).toStrictEqual(relationB.id);
|
||||||
|
|
||||||
|
const relationAWithDepth = await payload.findByID({
|
||||||
|
collection: 'relation-a',
|
||||||
|
id: relationA.id,
|
||||||
|
depth: 4,
|
||||||
|
});
|
||||||
|
|
||||||
|
const innerMostRelationship = relationAWithDepth.relationship.relationship.richText[1].value.relationship.relationship;
|
||||||
|
|
||||||
|
expect(typeof innerMostRelationship).toStrictEqual(relationB.id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user