Friday, January 8, 2010

Too Many StyleSheets

In building our app, the approach I used towards styling has very much been "shortest route to dogfood"[1].

To that end, every time I created a new UI widget, I would just create an empty css file for it and dump in any necessary style rules (for whatever reason, at the time this seemed the fastest way to do it).

That worked nice and dandy, until I got up to about 30 stylesheets. Suddenly, GWT hosted mode was no longer loading all of my styles, things were looking funny. I did a little experimentation and found that it was always loading precisely *31* stylesheets and then stopping. Wierd.

I wrote a post on the GWT forum about it, to see if anyone else had come across this limitation.

Within a couple of hours, Thomas Broyer wrote back that this was actually a well-known limitation of IE (the browser on which hosted mode is based).

Ha! Thanks Thomas!

Lesson learned, case closed. Path to dogfood hindered but not blocked. "I'll just keep going for now, knowing that I have to fix this later".



Two months later, GWT 2.0 is out and I'm going back through all my code, yanking out reams of boilerplate code thanks to the tremendously powerful and sexy UIBinder.

Just fo[sic] fun, I try loading the app in IE to see how it likes one of my newly-restyled widgets, and....



Runtime Error!


00:35:22.000 [ERROR] Unable to load module entry point class com.traveltripper.stargazer.client.Stargazer (see associated exception for details)
java.lang.AssertionError: null at com.google.gwt.dom.client.StyleInjector$StyleInjectorImplIE.injectStyleSheet(StyleInjector.java:132) at com.google.gwt.dom.client.StyleInjector.flush(StyleInjector.java:358) at com.google.gwt.dom.client.StyleInjector.access$1(StyleInjector.java:343) at com.google.gwt.dom.client.StyleInjector$1.execute(StyleInjector.java:195) at com.google.gwt.core.client.impl.SchedulerImpl$Task$.executeScheduled$(SchedulerImpl.java:50)
...


Sadly, the error in and of itself told me nothing... I had to actually open the StyleInjector.java file and hunt down to line 132.

And there it was, my old friend. Too many stylesheets! Google actually prevents you from breaking the css limit -- via an assertion failure.

Technically, my path to the dog food is still unblocked -- it only gives me this runtime error when I load the app in IE. But I think now's probably a good time to go back and do things the right way.

Hopefully this helps someone out there who might run into this same error.



[1] A phrase which I learned from my ex-colleague-extraordinaire Chris Schmidt, and which I discovered only today, searching for links, is *not* actually a common expression but rather something he must have made up. It is, however, pretty self-explanatory: it basically means doing whatever is the fastest, easiest thing you can do to get a job done.