-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Angular.js causes styled-components to break on IE 11 #657
Comments
Seeing the same issue with |
This is @geelen expertise, there's a reason why we do it exactly the way we do. I don't want to change that part of the code without having benchmarked it extensively to make sure we don't get less performant and I need @geelen to confirm this'll work so we avoid subtle ordering bugs like #1. (which are a pain) |
@mxstbr Ah, yep, you're right. If we defer injection to the rendering, then the order of CSS is going to change to the order of rendering, not the order of imports. Looks like this is not sth we'll fix anytime soon :/ |
@mxstbr @philpl this is definitely true. Maybe the best option in the meantime is just to do a check for if the For example: const selector = nameGenerator(hash)
inserted[hash] = selector
const root = parse(`.${selector} { ${flatCSS} }`)
postcssNested(root)
autoprefix(root)
+ if (this.textNode && !this.textNode.parentNode) {
+ console.warn('There may be an issue with the styles, the stylesheet DOM has been mutated.')
+ }
this.insertedRule.appendRule(root.toResult().css) |
It's not really sth that is a bug on our end, or sth that we can affect or fix unfortunately |
I've had this same problem with using styled-components in the angular/react app I'm working on. I found this snippet by @dfrankland that fixed my problem. angular.element(document).ready(() => {
const bootStrapElement = (
// BAD! Recompiles everything causing IE 11 to not work
document
// GOOD! Does not mess with the <head>
// document.body
);
angular.bootstrap(bootStrapElement, ['blah'], {});
}); https://github.com/dfrankland/styled-components-angular-ie-11-conflict/blob/master/src/main.js |
@jasonalmaturner Would u tell me what u changed?! |
- angular.bootstrap(document, ['blah'], {});
+ angular.bootstrap(document.body, ['blah'], {}); |
actually, I'm trying to fix my issue using this solution but I'm using react2angular to handle react components separately what I have to follow?! |
@HashemKhalifa, using Following the import { react2angular } from 'react2angular'
angular
.module('myModule', [])
.component('myComponent', react2angular(MyComponent, ['fooBar', 'baz']))
+ .element(document).ready(() => angular.bootstrap(document.body, ['myModule'], {})); If you need any other help, you may want to open an issue for |
@dfrankland Thanks for your reply, .element here refer to what? |
I think at this point you should consider opening an issue on their repo instead 😉 |
Hey everyone, someone even opened a repo to demostrate the bug, that when styled-component run with AngularJS in IE11, it breaks. Any fixes atm? really need it, super sad it happens... |
@adamchenwei To quote myself:
I don't really have time to look at it in detail, but the proposed fix confirmed it for me. If someone could explain why it happens and it turns out that it's a problem with our codebase, then we'd be able to actually fix it. |
Just a heads-up. If you use auto-bootstrapping with |
Version
1.4.4 (maybe a lot older too)
Reproduction
Webpackbin doesn't work on IE 11... So here's a repo!
https://github.com/dfrankland/styled-components-angular-ie-11-conflict
Steps to reproduce
Follow steps in linked repo.
Expected Behavior
Work like normal.
Actual Behavior
No CSS rules are applied to the style element.
Why?
Angular will recompile all the individual DOM elements including those in the head. Normally, on Chrome and other browsers this isn't an issue, but on IE 11 this causes text nodes to lose their
parentNode
. This could occur due to anything though, it doesn't have to be Angular. The more longwinded explanation:Style elements and text nodes get inserted in
ComponentStyle
Afterwards, anything could mutate the DOM, such as Angular, causing issues later
A styled component is ready to render so
generateAndInjectStyles
inside ofComponentStyle
is calledappendRule
inside the Glamor sheet tries to mutate a text node, but it has already been removed from the DOM, thus no styles are applied to the style tags created in step 1Fix
I propose to move the appending of text nodes to the style element DOM only once the component is ready to render, rather than doing it preemptively.
https://github.com/styled-components/styled-components/blob/master/src/vendor/glamor/sheet.js#L125
https://github.com/styled-components/styled-components/blob/master/src/models/ComponentStyle.js#L39
const selector = nameGenerator(hash) inserted[hash] = selector const root = parse(`.${selector} { ${flatCSS} }`) postcssNested(root) autoprefix(root) this.insertedRule.appendRule(root.toResult().css) + this.insertedRule.appendNode()
The text was updated successfully, but these errors were encountered: