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

SSR bug with nested components #801

Closed
Conduitry opened this issue Aug 30, 2017 · 0 comments · Fixed by #806
Closed

SSR bug with nested components #801

Conduitry opened this issue Aug 30, 2017 · 0 comments · Fixed by #806
Labels

Comments

@Conduitry
Copy link
Member

Looks like this arose with the <slot> changes. Compiling

<Outer>
	<Inner>Foo</Inner>
</Outer>
<script>
	export default { components: { Outer, Inner } }
</script>

in SSR mode produces

click to expand
'use strict';

var template = (function () {
	return { components: { Outer, Inner } }
}());

var SvelteComponent = {};

SvelteComponent.filename = "SvelteComponent.html";

SvelteComponent.data = function () {
	return {};
};

SvelteComponent.render = function ( state, options ) {
	state = state || {};

	return `
${template.components.Inner.render({}, { slotted: { default: () => `Foo` } })}
${template.components.Outer.render({}, { slotted: { default: () => `Foo`, null: () => `` } })}
`.trim();
};

SvelteComponent.renderCss = function () {
	var components = [];

	var seen = {};

	function addComponent ( component ) {
		var result = component.renderCss();
		result.components.forEach( x => {
			if ( seen[ x.filename ] ) return;
			seen[ x.filename ] = true;
			components.push( x );
		});
	}

	addComponent( template.components.Outer );
	addComponent( template.components.Inner );

	return {
		css: components.map( x => x.css ).join( '\n' ),
		map: null,
		components
	};
};

var escaped = {
	'"': '&quot;',
	"'": '&#39;',
	'&': '&amp;',
	'<': '&lt;',
	'>': '&gt;'
};

function __escape ( html ) {
	return String( html ).replace( /["'&<>]/g, match => escaped[ match ] );
}

module.exports = SvelteComponent;

<Inner> is rendered before <Outer>, instead of being passed as a slot. This only happens when <Inner> has its own child when used inside <Outer> (i.e., just <Outer><Inner/></Outer> doesn't seem to experience this). Only an issue with SSR so far as I can tell.

@Conduitry Conduitry changed the title SSR bur with nested components SSR bug with nested components Aug 30, 2017
Rich-Harris added a commit that referenced this issue Aug 31, 2017
Rich-Harris added a commit that referenced this issue Aug 31, 2017
stack up append targets so that slotted content in nested components works in SSR mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants