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

Null value is not handled in ObjectField #775

Closed
SicParv1sMagna opened this issue Jan 9, 2025 · 7 comments · Fixed by #809
Closed

Null value is not handled in ObjectField #775

SicParv1sMagna opened this issue Jan 9, 2025 · 7 comments · Fixed by #809

Comments

@SicParv1sMagna
Copy link
Contributor

I have a deeply nested component with some nullable values by default. When I make that values null this error occurres, which I guess is a bug.

image
@chrisvxd
Copy link
Member

chrisvxd commented Jan 9, 2025

@SicParv1sMagna can you share a code example, please?

@SicParv1sMagna
Copy link
Contributor Author

SicParv1sMagna commented Jan 9, 2025

I guess that's my mistake, objectfield doesn't have defaultValue props or something like that, besides default value for each element of object, isn't it?

If this statement correct, I will close this issue, because I add defaultValue to objectField in my components scheme parser

@chrisvxd
Copy link
Member

chrisvxd commented Jan 9, 2025

I could be persuaded that is a bug. The object field should probably be able to handle cases where the object is not defined.

@SicParv1sMagna
Copy link
Contributor Author

I can give full example only tomorrow, but I decided to use defaultValue like this:

const config = {
  components: {
    Example: {
      fields: {
        items: {
          type: "object",
          objectFields: {
            title: { type: "text" },
          },
        },
      },
      // ...
      defaultValue: {
          objectFields: {
             title: null
          }
      }
    },
  },
};

this is example, which was written by memory, i guess that it could be incorrect

@jmolivas
Copy link

jmolivas commented Jan 16, 2025

I am seeing the same error, I am fetching data form Drupal via GraphQL and some fields are defined as nullable

image

I added a helper function call to at defaultProps and resolveData to iterate object properties and replace null values as work around

  defaultProps: parse(Hero.defaultProps, parser),
  resolveData: async (data) => {
    return {
      props: replaceNullAndUndefined(data.props),
    }
  },

Once workaround it's applied it works as expected

image

Agree with @chrisvxd and seems like a bug and Puck should be smart enough to handle this.

@chrisvxd
Copy link
Member

This is actually a much more basic issue with the field implementation, and reproducible without objects. Even this basic case will trigger it. Interestingly, Puck does handle cases where the type is undefined.

const config = {
  components: {
    Example: {
      fields: {
        title: { type: "text" },
      },
      // ...
      defaultValue: {
        title: null
      }
    },
  },
};

Will roll out a fix now.

@chrisvxd
Copy link
Member

Addressed. Available in both 0.17.4 and 0.18.0 canaries. 0.17.4 will be released ASAP. 0.18.0 next week.

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

Successfully merging a pull request may close this issue.

3 participants