Merge pull request #377 from sveltejs/gh-372

revert to previous addCss behaviour
pull/384/head
Rich Harris 8 years ago committed by GitHub
commit 8e5125e0bd

@ -201,30 +201,16 @@ export default function dom ( parsed, source, options, names ) {
getUniqueName: generator.getUniqueNameMaker()
});
parsed.html.children.forEach( node => generator.visit( node ) );
generator.addRenderer( generator.pop() );
const builders = {
main: new CodeBuilder(),
init: new CodeBuilder(),
_set: new CodeBuilder()
};
if ( parsed.css && options.css !== false ) {
generator.current.builders.mount.addLine( `if ( !target.ownerDocument.__sveltecss_${parsed.hash} ) addCss( target.ownerDocument );` );
builders.main.addBlock( deindent`
function addCss ( document ) {
var style = ${generator.helper( 'createElement' )}( 'style' );
style.textContent = ${JSON.stringify( processCss( parsed, generator.code ) )};
${generator.helper( 'appendNode' )}( style, document.head );
document.__sveltecss_${parsed.hash} = true;
}
` );
}
parsed.html.children.forEach( node => generator.visit( node ) );
generator.addRenderer( generator.pop() );
if ( options.dev ) {
builders._set.addBlock ( deindent`
if ( typeof newState !== 'object' ) {
@ -267,11 +253,28 @@ export default function dom ( parsed, source, options, names ) {
builders.main.addBlock( `[✂${parsed.js.content.start}-${parsed.js.content.end}✂]` );
}
if ( parsed.css && options.css !== false ) {
builders.main.addBlock( deindent`
var addedCss = false;
function addCss () {
var style = ${generator.helper( 'createElement' )}( 'style' );
style.textContent = ${JSON.stringify( processCss( parsed, generator.code ) )};
${generator.helper( 'appendNode' )}( style, document.head );
addedCss = true;
}
` );
}
let i = generator.renderers.length;
while ( i-- ) builders.main.addBlock( generator.renderers[i] );
builders.init.addLine( `this._torndown = false;` );
if ( parsed.css && options.css !== false ) {
builders.init.addLine( `if ( !addedCss ) addCss();` );
}
if ( generator.hasComponents ) {
builders.init.addLine( `this._renderHooks = [];` );
}

@ -1,21 +0,0 @@
export default {
test ( assert, component, target, window ) {
const iframe = window.document.createElement('iframe');
window.document.body.appendChild(iframe);
const otherTarget = iframe.contentWindow.document.body;
new component.constructor({
target: otherTarget
});
assert.equal(
window.getComputedStyle(target.querySelector('h1')).color,
'rgb(255, 0, 0)'
);
assert.equal(
window.getComputedStyle(otherTarget.querySelector('h1')).color,
'rgb(255, 0, 0)'
);
}
};

@ -1,6 +0,0 @@
<h1>Just some static HTML</h1>
<style>
h1 {
color: rgb(255, 0, 0);
}
</style>
Loading…
Cancel
Save