mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
when creating a component, always check whether its css is still in the dom (#554)
This commit is contained in:
parent
1078bae696
commit
a1c8ada088
@ -117,13 +117,11 @@ export default function dom ( parsed, source, options ) {
|
|||||||
|
|
||||||
if ( generator.css && options.css !== false ) {
|
if ( generator.css && options.css !== false ) {
|
||||||
builders.main.addBlock( deindent`
|
builders.main.addBlock( deindent`
|
||||||
var ${generator.alias( 'added_css' )} = false;
|
|
||||||
function ${generator.alias( 'add_css' )} () {
|
function ${generator.alias( 'add_css' )} () {
|
||||||
var style = ${generator.helper( 'createElement' )}( 'style' );
|
var style = ${generator.helper( 'createElement' )}( 'style' );
|
||||||
|
${generator.helper( 'setAttribute' )}( style, ${JSON.stringify( generator.cssId )}, '' );
|
||||||
style.textContent = ${JSON.stringify( generator.css )};
|
style.textContent = ${JSON.stringify( generator.css )};
|
||||||
${generator.helper( 'appendNode' )}( style, document.head );
|
${generator.helper( 'appendNode' )}( style, document.head );
|
||||||
|
|
||||||
${generator.alias( 'added_css' )} = true;
|
|
||||||
}
|
}
|
||||||
` );
|
` );
|
||||||
}
|
}
|
||||||
@ -135,7 +133,7 @@ export default function dom ( parsed, source, options ) {
|
|||||||
builders.init.addLine( `this._torndown = false;` );
|
builders.init.addLine( `this._torndown = false;` );
|
||||||
|
|
||||||
if ( parsed.css && options.css !== false ) {
|
if ( parsed.css && options.css !== false ) {
|
||||||
builders.init.addLine( `if ( !${generator.alias( 'added_css' )} ) ${generator.alias( 'add_css' )}();` );
|
builders.init.addLine( `if ( !document.querySelector( 'style[${generator.cssId}]' ) ) ${generator.alias( 'add_css' )}();` );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( generator.hasComponents || generator.hasIntroTransitions ) {
|
if ( generator.hasComponents || generator.hasIntroTransitions ) {
|
||||||
|
@ -8,13 +8,11 @@ var template = (function () {
|
|||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
var added_css = false;
|
|
||||||
function add_css () {
|
function add_css () {
|
||||||
var style = createElement( 'style' );
|
var style = createElement( 'style' );
|
||||||
|
setAttribute( style, "svelte-3842350206", '' );
|
||||||
style.textContent = "\n\tp[svelte-3842350206], [svelte-3842350206] p {\n\t\tcolor: red;\n\t}\n";
|
style.textContent = "\n\tp[svelte-3842350206], [svelte-3842350206] p {\n\t\tcolor: red;\n\t}\n";
|
||||||
appendNode( style, document.head );
|
appendNode( style, document.head );
|
||||||
|
|
||||||
added_css = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_main_fragment ( state, component ) {
|
function create_main_fragment ( state, component ) {
|
||||||
@ -59,7 +57,7 @@ function SvelteComponent ( options ) {
|
|||||||
this._yield = options._yield;
|
this._yield = options._yield;
|
||||||
|
|
||||||
this._torndown = false;
|
this._torndown = false;
|
||||||
if ( !added_css ) add_css();
|
if ( !document.querySelector( 'style[svelte-3842350206]' ) ) add_css();
|
||||||
|
|
||||||
this._fragment = create_main_fragment( this._state, this );
|
this._fragment = create_main_fragment( this._state, this );
|
||||||
if ( options.target ) this._fragment.mount( options.target, null );
|
if ( options.target ) this._fragment.mount( options.target, null );
|
||||||
@ -85,4 +83,4 @@ SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = functio
|
|||||||
this._torndown = true;
|
this._torndown = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SvelteComponent;
|
export default SvelteComponent;
|
||||||
|
Loading…
Reference in New Issue
Block a user