Like what we’re doing? Star us on GitHub!

TypeError When viewing Versions

TheDunco
4 weeks ago
24

TypeError: Cannot read properties of undefined (reading 'label')



Whenever I go to specific Versions documents I get this error. I'm unsure as to exactly what causes the error because the Admin UI goes completely blank whenever I get it. It only happens on certain versions of documents. I've solved similar problems in validation functions that usually require adding a missing question mark (

?.label

) but am unsure of exactly where the error is coming from or what causes it so I'm not sure how to provide more context. Could this be because of a validation function or something I have written? Or is it a Payload issue? I would assume it's a Payload issue because it's in a document's Versions which I haven't messed with besides enabling them.



Included in the pictures is an example of a Version document that's breaking when I try to view it in the Admin UI. If there's any other information I can provide please let me know!

image.png
image.png
  • jesschow
    Payload Team
    4 weeks ago

    Hi @TheDunco - what version of payload are you on? we will try to replicate this

  • TheDunco
    4 weeks ago

    Hi! I've been experiencing this since Payload ^1.5 and am still experiencing it on v1.6.11 which is the version I'm currently running

  • jmikrut
    Payload Team
    4 weeks ago

    @TheDunco this is in production, right? Any way to replicate this issue in development so that the error message is more helpful?



    Alternatively, you could click on the top line in your error message to see where the error is coming from within the compiled code

  • TheDunco
    4 weeks ago

    Ah yes, sorry, my original message contained what it looked like in development...

    image.png
  • jmikrut
    Payload Team
    4 weeks ago

    @dribbens something to look into here probably regarding

    getTranslatedOptions


    probably a case of having bad data, BUT, we should be able to make that function "safer" so that it won't crash

  • dribbens
    Payload Team
    4 weeks ago

    I was thinking the same.



    I'll take a đź‘€ . Might have trouble without steps to reproduce.

  • TheDunco
    4 weeks ago

    It seems to me like adding optional chaining and/or ternaries to wherever the

    field.label

    is accessed in that file should solve my particular issue. Is there a way to build and use the Payload dep locally so I could try this out myself?



    Otherwise improving the safety of that function overall should fix the issue, but if it would help to narrow it down since I can't provide steps to reproduce I'm willing to try that

  • jmikrut
    Payload Team
    4 weeks ago

    yes, you just need a local Mongo running. from there, just pull down Payload and run

    yarn dev versions

    to get a versions test environment set up



    but you can run

    yarn dev [any-test-folder]

    and develop against a lot of stuff. in this case,

    versions

    is the move for you i'd expect

  • TheDunco
    4 weeks ago

    Sweet, thanks! I was just checking and I'm actually having trouble reproducing myself, but this is an issue I've seen all over the place. Just kinda hard to nail down. I checked the document that was previously causing issues and it doesn't seem to be an issue anymore, although there seem to be less versions now than before when it was causing issues 🤷



    This is in production and I have multiple designers working on it so someone else probably messed with it and fixed it unwittingly

  • dribbens
    Payload Team
    4 weeks ago

    I thought I found where this could be happening but after some testing I couldn't reproduce it.



    Oh nvm, I think I know



    I believe it is because this function could return null from a

    find

    not working if options have changed on the collection config.


    https://github.com/payloadcms/payload/blob/d9d2b6c383b55d570473f66bbf5dcfc669bb168b/src/admin/components/views/Version/RenderFieldsToDiff/fields/Select/index.tsx#L15


    This file could be cleaned up, looks like I got kind of wild on it.



    I can sort this out, but not right now.

  • TheDunco
    4 weeks ago

    Cool, thanks for looking into this! It's not super urgent, just thought I'd report!

  • dribbens
    Payload Team
    3 weeks ago

    Issue created:

    https://github.com/payloadcms/payload/issues/2162

    and I have a PR that addresses this:

    https://github.com/payloadcms/payload/pull/2163

    That will be released probably next week.

  • TheDunco
    3 weeks ago

    Awesome, thank you!



    I'm glad you were able to figure out that it was related to changing options in select fields, that's definitely what broke things for me

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More