#transformProps makes root default value error

1 messages · Page 1 of 1 (latest)

novel sparrow
#

Hi, I want to ask about transformProps. It is causing error like in the image

Warning: Defining props on `root` is deprecated. Please use `root.props`, or republish this page to migrate automatically.

Right now, if I have transformProps for root like this

  root: (props) => {
    console.log("Transforming", props)
    const a = (
      {
        ...props,
        root: {
          ...rootDefaultValue, ...props.root,
          hehe: "hoho",
        }
      }
    )
    return a;
  },

And it produces root data like so

{
  "root": {
    "root": {
      "hehe": "hoho",
    },
    "props": {
      "root": {
        "hehe": "hoho",
      }
    }
  },
  "content": [],
  "zones": {}
}

I think the transformProps transforming data both inside and outside "props" field. And it causes that error because defining props on "root" is deprecated.

If after getting that data, I execute "migrate" function, it then works fine,

{
  "root": {
    "props": {
      "root": {
        "hehe": "hoho",
      }
    }
  },
  "content": []
}

Is this an expected bug? I don't want to "migrate" the data everytime right? 🤔

gloomy lily
#

Hey @novel sparrow! I don't know why you're getting this behavior, I can't replicate it.

Here's the example I used:

const rootDefaultValue = { hehe: "huhu" };

const data = {
  root: { props: { root: { someOtherProp: "" } } },
  content: [],
  zones: {},
};

const newData = transformProps(data, {
  root: (props) => {
    const a = {
      ...props,
      root: { ...props.root, ...rootDefaultValue, hehe: "hoho" },
    };

    return a;
  },
});

console.log(newData)

This outputs:

{
  "root": {
    "props": {
      "root": {
        "someOtherProp": "",
        "hehe": "hoho"
      }
    }
  },
  "content": [],
  "zones": {}
}

I think the cause of your issue might be coming from something related to how you're handling the data object afterwards (there could be some object reference problems too).

novel sparrow
# gloomy lily Hey <@377000778453483540>! I don't know why you're getting this behavior, I can'...

Hi @gloomy lily , sorry for not mentioning I use Puck 0.19.3,

With your example, yes it works good, but I can replicate it with your example in mine, with tweaked value where the data is empty array {} (I use {} for the initial data)

const data = {};
const newData = transformProps(data, {
  root: (props) => {
    const a = {
      ...props,
      root: { ...props.root, ...rootDefaultValue, hehe: "hoho" },
    };

    return a;
  },
});
console.log(newData)

I now get a result like this. It only fills in "root", instead of root.props 🤔
Result :

{
  "root": {
    "root": {
      "hehe": "hoho"
    }
  },
  "content": [],
  "zones": {}
}