Bad error message when `load` returns falsy from layout
See original GitHub issueDescribe the bug
When returning nothing in a load function (as perceived to be permitted by the docs ) an error is thrown that doesn’t pin point the actual issue - which may not even need to be one - which is that I wrote return;
at the end of the load function instead of return {};
Logs Cannot read property ‘error’ of undefined TypeError: Cannot read property ‘error’ of undefined at normalize (node_modules/@sveltejs/kit/dist/ssr.js:517:13) at load_node (node_modules/@sveltejs/kit/dist/ssr.js:829:11) at async respond_with_error (node_modules/@sveltejs/kit/dist/ssr.js:904:17) at async respond$1 (node_modules/@sveltejs/kit/dist/ssr.js:1119:13) at async render_page (node_modules/@sveltejs/kit/dist/ssr.js:1186:20) at async render (node_modules/@sveltejs/kit/dist/ssr.js:1537:10) at async Object.handle (/src/hooks:26:19) at async respond (node_modules/@sveltejs/kit/dist/ssr.js:1510:10) at async Immediate.<anonymous> (node_modules/@sveltejs/kit/dist/chunks/index.js:3305:23)
To Reproduce
in any @type {import('@sveltejs/kit').Load}
function, change current return value to return;
Expected behavior To set default object with status 200
Information about your SvelteKit Installation:
Diagnostics
System: OS: macOS 11.3.1 CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz Memory: 172.27 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node npm: 7.12.1 - ~/.nvm/versions/node/v14.15.4/bin/npm Browsers: Chrome: 90.0.4430.212 Firefox: 87.0 Safari: 14.1 npmPackages: @sveltejs/kit: next => 1.0.0-next.107 svelte: ^3.34.0 => 3.38.2Severity Not severe, easily fixable.
Additional context If this is by design, perhaps the docs could be updated to reflect this? With it currently saying that all keys are optional you’d assume you wouldn’t have to pass an empty object to an all optional object but rather nothing at all.
Thanks for all the hard work!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
The error message for this is dramatically better now. I think it got updated when I turned on strict typing for TypeScript in the most recent releases. Now it says:
The main issue remaining here is that it just shows it on a blank page instead of the normal error page:
https://github.com/sveltejs/kit/blob/2a1e9795ad9773e04669a7b9d0234caa0b688ade/packages/kit/src/runtime/server/page/load_node.js#L269
But I guess that happens because since this error is on a layout page it occurs on the error page and so since the error page can’t be rendered it just shows a blank page with the error. I don’t have any ideas how to do that differently, so am going to call this one solved
Ah I see. I think this is probably a bug, yeah, but I’ll let Rich weigh in. For route fallthrough purposes, I can’t see a reason why you’d want different behavior when returning falsy from a layout load.