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

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

Closed
zaydek opened this issue Feb 8, 2021 · 3 comments

Comments

@zaydek
Copy link

zaydek commented Feb 8, 2021

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

@neurocmd
Copy link

neurocmd commented Apr 2, 2021

This is a very huge bug. I came across the same problem. On server side I get <img src="some.jpg" srcset="undefined"> instead <img src="some.jpg"> and it breaks an image because srcset takes precedence over src. Therefore, users with javascript disabled and Google won`t see images. Are there any insurmountable obstacles to fix this bug?

@stale
Copy link

stale bot commented Jul 1, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jul 1, 2021
@stale
Copy link

stale bot commented Jul 15, 2021

This issue has been closed as it was previously marked as stale and saw no subsequent activity.

@stale stale bot closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants