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

Error: Cannot read properties of undefined (reading 'map') #5

Closed
hyldmo opened this issue Oct 6, 2023 · 2 comments · Fixed by #11
Closed

Error: Cannot read properties of undefined (reading 'map') #5

hyldmo opened this issue Oct 6, 2023 · 2 comments · Fixed by #11

Comments

@hyldmo
Copy link
Contributor

hyldmo commented Oct 6, 2023

Hello, my entire dashboard is crashing after installing this package. Here's the stack trace:

Error: Cannot read properties of undefined (reading 'map')
TypeError: Cannot read properties of undefined (reading 'map')
    at getBaseFields (http://localhost:3333/node_modules/.sanity/vite/deps/@sanity_assist.js?v=aeff8c73:2910:87)
    at getSchemaStub (http://localhost:3333/node_modules/.sanity/vite/deps/@sanity_assist.js?v=aeff8c73:2899:8)
    at http://localhost:3333/node_modules/.sanity/vite/deps/@sanity_assist.js?v=aeff8c73:2866:203
    at Array.map (<anonymous>)
    at serializeSchema (http://localhost:3333/node_modules/.sanity/vite/deps/@sanity_assist.js?v=aeff8c73:2866:192)
    at http://localhost:3333/node_modules/.sanity/vite/deps/@sanity_assist.js?v=aeff8c73:3758:49
    at mountMemo (http://localhost:3333/node_modules/.sanity/vite/deps/chunk-XL3JYWLG.js?v=aeff8c73:13169:27)
    at Object.useMemo (http://localhost:3333/node_modules/.sanity/vite/deps/chunk-XL3JYWLG.js?v=aeff8c73:13513:24)
    at useMemo (http://localhost:3333/node_modules/.sanity/vite/deps/chunk-ZD3M55OV.js?v=aeff8c73:1091:29)
    at useRunInstructionApi (http://localhost:3333/node_modules/.sanity/vite/deps/@sanity_assist.js?v=aeff8c73:3758:42)

I suspect it is because I have some non standard list options (for instance the list parameter in my setup accepts promises for list items fetched somewhere else). Would it be possible to add a bit stricter type check on https://github.com/sanity-io/assist/blob/725164766422d2f7ff2b1c82777353ed08b70205/plugin/src/schemas/serialize/serializeSchema.ts#L86C1-L87C1 ?
a simple replacement of values: type?.options?.list to values: type?.options?.list?.map or values: typeof type?.options?.list?.map === 'function' should suffice for my needs.

I apologize as I know this is non-standard/unsupported behavior, but hopefully the code change should be small enough and of the type that doesn't really introduce tech debt. Happy to submit a PR myself if that helps.

@snorrees
Copy link
Contributor

Hey, sorry about this. Would love a PR, possibly checking for Array.isArray(type?.options?.list) as the guard?

@hyldmo
Copy link
Contributor Author

hyldmo commented Oct 10, 2023

Thank you for the response. I added a PR with a suggested fix now.

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

Successfully merging a pull request may close this issue.

2 participants