Skip to content

[Bug] Destructuring {...$props} on an element does not omit undefined attributes #5969

Closed
@zaydek

Description

@zaydek

Bug
In SSR mode, <a target={true ? undefined : "..."} {...$$props}> renders <a target="undefined"> instead of <a>. This does not appear to happen when {...$$props} is not present.

Expected behavior
The expected behavior is that undefined attributes should be omitted. These are PRs that I found are similar in scope:

#1668
#4498
#1815

Repro
I created a repro to demonstrate my use case: https://github.com/zaydek/svelte-undefined-bug. Simply run yarn test or npm run test to see the same result as in the screenshot.

Furthermore, in this repl: https://svelte.dev/repl/aaedb6456d714a9f9ccfab9c84c8b391?version=3.32.1, when SSR mode is enabled, you can see that it generates:

const App = create_ssr_component(($$result, $$props, $$bindings, slots) => {
	return `<a${spread([
		{
			target: escape(true ? undefined : "_blank")
		},
		$$props
	])}>Hello, world!
</a>`;
});

I suspect escape is the culprit; it should be omitting the value instead of escaping it as a string literal.

Screen Shot 2021-02-09 at 3 18 09 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions