Skip to content

Backtick/grave (`) in component breaks SSR render method #616

@taylorzane

Description

@taylorzane

When a backtick/grave accent is used in a component, and one uses generate: 'ssr', the output function breaks due to the render() method using backticks to allow for a multi-line string.

This also appears to fail with the HTML escaped representation of the grave (`) as svelte evaluates it back to a backtick.

Smallest failing example:

<code>
const url = `${protocol}://duckduckgo.com`
</code>
<!-- OR -->
<code>
const url = &#96;${protocol}://duckduckgo.com&#96;
</code>

Output:

MyComponent.render = function ( root, options ) {
	root = root || {};

	return `<code>const url = `\${protocol}://duckduckgo.com`</code>`;
};

I'm not sure how the generator determines to use template strings vs double-quotes, because it seems like it differs (unless I was looking at different functions at the time).

Workaround: "Escape" the backticks in the component html file.

Input:

<code>
const url = \`${protocol}://duckduckgo.com\`
</code>

Output:

MyComponent.render = function ( root, options ) {
	root = root || {};

	return `<code>const url = \`\${protocol}://duckduckgo.com\`</code>`;
};

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions