Description
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:
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.