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

Set CSS text after style element is added to DOM, to fix crash on IE < 9... #2000

Merged
merged 1 commit into from
May 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/less/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ function createCSS(styles, sheet, lastModified) {
}
css.id = id;

if (css.styleSheet) { // IE
try {
css.styleSheet.cssText = styles;
} catch (e) {
throw new(Error)("Couldn't reassign styleSheet.cssText.");
}
} else {
if (!css.styleSheet) {
css.appendChild(document.createTextNode(styles));

// If new contents match contents of oldCss, don't replace oldCss
Expand All @@ -148,6 +142,17 @@ function createCSS(styles, sheet, lastModified) {
oldCss.parentNode.removeChild(oldCss);
}

// For IE.
// This needs to happen *after* the style element is added to the DOM, otherwise IE 7 and 8 may crash.
// See http://social.msdn.microsoft.com/Forums/en-US/7e081b65-878a-4c22-8e68-c10d39c2ed32/internet-explorer-crashes-appending-style-element-to-head
if (css.styleSheet) {
try {
css.styleSheet.cssText = styles;
} catch (e) {
throw new(Error)("Couldn't reassign styleSheet.cssText.");
}
}

// Don't update the local store if the file wasn't modified
if (lastModified && cache) {
log('saving ' + href + ' to cache.', logLevel.info);
Expand Down