mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

Fix "Cannot find stylesheet" error on GoogleChrome #1007

Open saulocastelo opened 10 years ago

saulocastelo commented 10 years ago

Signed-off-by: Saulo Castelo Sampaio saulocastelo@gmail.com

SimplGy commented 9 years ago

This is nice. :)

SimplGy commented 9 years ago

Except... isn't it going to get sheets twice if both document.styleSheets and $("head").find('style') methods work?

GerHobbelt commented 9 years ago

For reference: original issue is #223

And @SimpleAsCouldBe: yes, the code produces the styles list twice. This is not a grave issue as the calling code does this (click 'expand' to see the 'break;' line in the github diff view):

         var sheets = getAllStyleSheets();
         for (var i = 0; i < sheets.length; i++) {
           if ((sheets[i].ownerNode || sheets[i].owningElement) == $style[0]) {
             stylesheet = sheets[i];
             break;
           }
         }

so only one instance is picked and worked with.

saulocastelo commented 9 years ago

I will submit a better way to do this because the getAllStyleSheets function should not return repeated styles. Just wait.

saulocastelo commented 9 years ago

Done. Take a look.

SimplGy commented 9 years ago

Is there a way to accomplish this by testing capability instead of user agent?

navigator.userAgent.toLowerCase().indexOf('chrome')

A UA test is fragile here because:

  1. Chrome could change. Chrome is an evergreen browser. They could change this behavior at any time.
  2. This might not cover all browsers who show this behavior. If chrome behaves this way with stylesheets, why wouldn't other webkit browsers?
saulocastelo commented 9 years ago

I agree, I already have an idea, just wait.

saulocastelo commented 9 years ago

Guys, i was thinking about the function createCssRules, you are appending the rule directly to the head tag. So we don't even need to test if the bug exists, we should just read the rules directly from the head tag.

Did you guys agree? If so, I will make the changes and commit.

Sorry my delay, I was very busy.

bcherny commented 8 years ago

testing this locally with a few grids on the page, and re-rendering them a few times, this fix doesn't seem to work :(

saulocastelo commented 8 years ago

Can you send me your test page?