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

Confusing SSR error when let:foo has no corresponding <slot foo={...}> #3322

Closed
Rich-Harris opened this issue Jul 31, 2019 · 0 comments · Fixed by #3428
Closed

Confusing SSR error when let:foo has no corresponding <slot foo={...}> #3322

Rich-Harris opened this issue Jul 31, 2019 · 0 comments · Fixed by #3428
Labels

Comments

@Rich-Harris
Copy link
Member

Describe the bug

A component with slotted contents will fail to render if it has a let: directive but the corresponding <slot> has no properties.

To Reproduce

This REPL demo contains the bug, though it's not directly visible since it's SSR-only. The offending code is this:

	return `${$$slots.default ? $$slots.default() : ``}`;

$$slots.default corresponds to this:

	return `${validate_component(Foo, 'Foo').$$render($$result, {}, {}, {
		default: ({ id }) => `
		${validate_component(Bar, 'Bar').$$render($$result, { thing: things[id] }, {}, {})}
	`
	})}`

This fails with

TypeError: Cannot destructure property id of 'undefined' or 'null'.

Expected behavior

It might be nice if a warning was printed about the missing property. But the easy immediate fix is to always pass an object, i.e. $$slots.default({}). This way there's no disparity between <slot> and <slot someOtherProperty="whatever">.

Severity

Minor annoyance

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

Successfully merging a pull request may close this issue.

1 participant