Barelydead / strapi-plugin-populate-deep

A Strapi plugin that makes it easier to populate deep content structures
175 stars 43 forks source link

Component not being populated in strange behavior #41

Closed Norbz closed 2 months ago

Norbz commented 1 year ago

Hi

I've encountered an issue where one of our component isn't being populated (there's a missing "cover" media field) no matter what depth we specify. The said component is in a dynamic zone.

The strange thing is that the bug occurs on a singleType that is almost the duplication of another collectionType that is working perfectly.

Here is the definition of the faulty singleType

{
  "kind": "singleType",
  "collectionName": "homepages",
  "info": {
    "singularName": "homepage",
    "pluralName": "homepages",
    "displayName": "🏠 Homepage",
    "description": ""
  },
  "options": {
    "draftAndPublish": false
  },
  "pluginOptions": {
    "url-alias": {
      "enabled": false
    }
  },
  "attributes": {
    "definition": {
      "type": "string",
      "required": true
    },
    "featuredlink": {
      "type": "component",
      "repeatable": false,
      "component": "texts.button"
    },
    "hero": {
      "type": "media",
      "multiple": false,
      "required": true,
      "allowedTypes": [
        "images"
      ]
    },
    "title": {
      "type": "string",
      "required": true
    },
    "content": {
      "type": "dynamiczone",
      "components": [
        "data.custom-editorial-list",
        "data.custom-project-list",
        "data.editorial-list",
        "data.event-list",
        ...
      ]
    }
  }
}

The component data.custom-project-list is missing it's cover field. I've switched the homepage into a collectionType without any success. In any case does the populate param include this : [content][populate][items][populate][cover]=true

The "working" collectionType has the same dynamic zone with the same components, same name (content), just different fields around... I've forked the plugin and traced everything, I cannot understand the differences between my two content-types in terms of behavior from the plugin...

Does anyone has any issue similar to this ?

HonzaTuron commented 1 year ago

Hello @Norbz. We had similar issues within our dynamic zone component. Following patch fixed it.

diff --git a/node_modules/strapi-plugin-populate-deep/server/helpers/index.js b/node_modules/strapi-plugin-populate-deep/server/helpers/index.js
index 7f026b8..2a95ea9 100644
--- a/node_modules/strapi-plugin-populate-deep/server/helpers/index.js
+++ b/node_modules/strapi-plugin-populate-deep/server/helpers/index.js
@@ -1,4 +1,4 @@
-const { isEmpty, merge } = require("lodash/fp");
+const { isEmpty, mergeWith } = require("lodash/fp");

 const getModelPopulationAttributes = (model) => {
   if (model.uid === "plugin::upload.file") {
@@ -32,7 +32,7 @@ const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => {
       } else if (value.type === "dynamiczone") {
         const dynamicPopulate = value.components.reduce((prev, cur) => {
           const curPopulate = getFullPopulateObject(cur, maxDepth - 1);
-          return curPopulate === true ? prev : merge(prev, curPopulate);
+          return curPopulate === true ? prev : mergeWith(prev, curPopulate, (obj, src) => ({ ...obj, ...src }));
         }, {});
         populate[key] = isEmpty(dynamicPopulate) ? true : dynamicPopulate;
       } else if (value.type === "relation") {

strapi-plugin-populate-deep+3.0.0.patch