[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 |
dummdidumm
left a comment
There was a problem hiding this comment.
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.
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.
| `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 |
|
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
jsonnew ErrorPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0