-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[fix] show more descriptive error if data returned from load
is a non-POJO
#7386
Conversation
🦋 Changeset detectedLatest commit: 4cf5e43 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks mostly good, added some small comments
const nonPojoError = /pojo/i.exec(error.message); | ||
|
||
if (nonPojoError) { | ||
const constructorName = branch[0]?.server_data?.data?.constructor?.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be from server_data deeper in the load tree, so I think it should be
const constructorName = branch[0]?.server_data?.data?.constructor?.name; | |
const constructorName = branch.find(({ server_data }) => server_data?.data?.constructor?.name)?.server_data.data.constructor.name; |
`Data returned from \`load\` must be a plain object${ | ||
constructorName ? ` rather than ${constructorName} constructor` : '' | ||
}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`Data returned from \`load\` must be a plain object${ | |
constructorName ? ` rather than ${constructorName} constructor` : '' | |
}` | |
`Data returned from \`load\` (while rendering ${event.routeId}) must be a plain object${ | |
constructorName ? ` rather than an instance of ${constructorName}` : '' | |
}` |
Thanks @dummdidumm, updated. |
load
is a non-POJO
Could you add a changeset by running |
Added changeset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Hey! I was trying to return a response with headers in a load, silly me. Now I understand how load works, but I noticed that I'm getting the old error when returning a response with headers and not the new one. Is this case in the scope of the pull request? Code: (+page.server.ts)
Error: Cannot stringify arbitrary non-POJOs (data.headers) |
Closes #7262
json
new Error
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0