Unverified Commit c88898be authored by Artur Muller's avatar Artur Muller Committed by GitHub

Clarify error message in isSerializableProps (#22856)

I recently received the "Props must be returned as a plain object" error when I accidentally dropped an array directly inside `props`. This is a trivial error to fix once you know what you did, but I spent good 30 minutes looking in all the wrong places. I hope that this slight clarification in the error message would save someone from wasting their time if they make a similar mistake like myself.
parent 270559f7
const regexpPlainIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/ const regexpPlainIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/
function getObjectClassLabel(value: any): string {
return Object.prototype.toString.call(value)
}
function isPlainObject(value: any): boolean { function isPlainObject(value: any): boolean {
if (Object.prototype.toString.call(value) !== '[object Object]') { if (getObjectClassLabel(value) !== '[object Object]') {
return false return false
} }
...@@ -19,7 +23,9 @@ export function isSerializableProps( ...@@ -19,7 +23,9 @@ export function isSerializableProps(
page, page,
method, method,
'', '',
`Props must be returned as a plain object from ${method}: \`{ props: { ... } }\`.` `Props must be returned as a plain object from ${method}: \`{ props: { ... } }\` (received: \`${getObjectClassLabel(
input
)}\`).`
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment