Anecdote on client-script compatibility issues

Anecdote on client-script related compatibility issues with ASP.NET v2.0 and some interesting personal observations...

We're gathering real-world feedback relating to compatibility with .net 2.0 with compat devlabs, with folks coming over to Redmond, and now with people from the team going out to customer sites as well.

One trip report I saw caught my eye: 4 out of 5 customers had their asp.net v1.x apps broken with script errors when they transitioned to asp.net v2.0. Not a good statistic. The primary issue with each of these apps was their client scripts referencing the form element via document._formName_ resulted in script errors. Turns out in v1 we rendered the name attribute in addition to the id attribute on the <form> tag, which allowed this script to work. The name attribute happens to be illegal in XHTML1.1 strict and so we render just the id attribute in v2 in this mode. With the new rendering, the correct script needed to access the form element is document.forms['_formID']. The workaround was to turn off XHTML1.1 rendering, or obviously require the app to be updated with new script. Both are sort of sucky.

At that point, I wondered if we could actually do some magic with script, and proposed we output the following:

    <script>
    document._formName_ = document.forms['_formID'];
    </script>

Apparently this worked! So we could output this in our XHTML1.1 rendering, and allow a number of scripts to continue running without changes.

As you try out beta 2, do report any compatibility issues you run into. We'd love to hear about them, and make sure those issues are addressed appropriately, whether its with creative solutions, code changes, adding compatibility switches, or at the very least, documenting them.

 

A couple of side notes on this solution that I thought were interesting to me personally...

  1. First, basically the workaround works by introducing a new expando property on the document object that would have otherwise existed by virtue of the name attribute on the <form> tag. Basically, this is capitalizing on the hacky nature of HTML and script, in this case, specifically the error-inducing-auto-expando-creation-on-typo behavior (as I like to call it - I've personally cursed on multiple occasions in the past when writing script and spent hours trying to debug why something wasn't quite working the way it should). I find it especially ironic capitalizing on this same behavior to come up with a solution. I guess that comes with the platform that is DHTML...
  2. Apparently injecting this script automatically for XHTML1.1, breaks the WCAG accessibility guidelines, which flag any script occurrence as an error. One of our PMs was quick to point that out. This is one of the most bizzare guidelines I've ever seen - in my opinion something that looks at all script generically and flags it as invalid only points to a badly designed guideline with an equally incomplete verification story and tools (to put it mildly). I've ranted on the subject several times in our internal discussions, as well as in a previous post. Anyway, we're probably going to have to do some additional thinking on this particular compat-issue: Should we not default to XHTML1.1 strict? Should we have a way to switch between XHTML flavors? Should we have yet another switch for whether or not to output the name attribute or this workaround script? etc. etc. Any thoughts?

Posted on Wednesday, 5/4/2005 @ 12:27 PM | #ASP.NET


Comments

11 comments have been posted.

Jim Geurts

Posted on 5/4/2005 @ 1:32 PM
I think it should default to xhtml 1.1 strict. Doing so will make the web [code] a better place and hopefully make browser compatibiliity issues less problematic in the future.

I disagree with offering a workaround... allowing people to code like slobs doesn't really help things. Yeah, they'll be able to upgrade without "errors," but they won't realize that they're not coding to the correct specification.

If they want to be xhtml1.1 compliant, then they should be forced (or highly recommended) to use the syntax that IS xhtml compliant... if they want to use a hack so that they can be lazy and not learn the updated syntax, leave that up to them to disable the syntax check. If the syntax engine does run into something like this, how about offering a suggestion to convert it to work with xhtml 1.1.

Derek Simon

Posted on 5/4/2005 @ 4:27 PM
The WCAG are just that-- guidelines. There are few cases where every page will meet every guideline. To say that a page isn't accessible simply because it contains script is narrow-sighted at best, regardless of whether the person assessing the code, on their own, determines it to be as such, or relies on the guidelines as absolute.

Cory Isakson

Posted on 5/4/2005 @ 7:58 PM
I agree with Jim. Stick with xhtml 1.1 strict. Developers need to clean their code. Don't compromise industry standards in the effort to be backward compatible with everything. We understand there will be a few issues as we move forward with new technologies.

Sergio Pereira

Posted on 5/5/2005 @ 5:19 AM
I also agree with Jim Geurts on the workaround. If you give this workaround now, people would keep writing invalid script and you will have to support this workaround going forward.
What the developers need to understand is that it was not ASP.NET that changed, but the document specification itself. If you wnat to target a specific document format, you better learn it and write your scripts accordingly.
Maybe a more interesting workaround (thinking out loud here) would be to include a protected method (or readonly property) that returns the string "document . forms ['FORM_ID_HERE'] " so if the developers what to hack-a-fix their scripts they can add the expando property themselves.
I know you want the upgrade to be more transparent to them, but if your target format moved from HTML to XHTML then its not really the same kind of application as before the upgrade. Make sure you render the "name" attribute if the target is HTML.

Milan Negovan

Posted on 5/5/2005 @ 7:47 AM
Nikhil, by golly, please don't bank on XHTML 1.1! It's a whole different ballgame. This is what I'm trying to tell Microsoft : http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=f14df26e-24aa-4dbc-9d9f-79f13341f1ba (sorry for the giant link).

XHTML 1.0 and 1.1 are not only a small increase in version. Support for 1.1 is flaky, and should you default to it, you'll be in for some unpredictable funkiness. Besides, you should serve XHTML 1.1 with the "application/xhtml+xml" MIME type (see http://www.w3.org/International/articles/serving-xhtml/) which nobody is prepared for, unless you can guarantee that every single server control produces drop dead valid XML which is unrealistic.

I'm lobbying Microsoft to add XHTML 1.0 Strict to the list of DTDs, right where it belongs. It's a much better choice than XHTML 1.1. I'm sorry, but given the state of XHTML 1.1 spec and its acceptance, "stick to XHTML 1.1" just won't work for another couple of years. I believe the most viable default for now is XHTML 1.0 Transitional. Hard core developers are welcome to switch to XHTML 1.0 Strict.

Oh, I do agree the accessibility guidelines are mindless at times.

Milan Negovan

Posted on 5/5/2005 @ 7:51 AM
By the way, there's no XHTML 1.1 Strict schema per se (see http://www.w3.org/QA/2002/04/valid-dtd-list.html). It's the one and only. :)

Nikhil Kothari

Posted on 5/5/2005 @ 10:26 AM
Ah... as always, XHTML proves an interesting subject!

I agree, sometimes moving forward is important (as a developer I wish more often than not that is would be the case), but given where we are: in the platform and framework business, allowing customers to transition applications at their own pace is also a good thing, rather than blocking migration and forcing upon required changes. I am reasonably sure the majority folks affected by a change wouldn't be against making the required changes and moving on, but a lot of them would also appreciate our efforts to try and ensure they can do so at the right time.

Hopefully we will resolve this particular issue soon. As of now, it is looking like we might default to XHTML 1.0 Transitional, and allow developers to choose strict if they desire to do so (similar to what you mention, Milan). Hopefully that provides the best default value, and enough flexibility for those who need it. We're meeting next week to look at options and finalize. I'll post an update if something different comes out of it.

Milan Negovan

Posted on 5/5/2005 @ 10:56 AM
XHTML 1.0 Transitional is lenient enough to accommodate deprecated tags as well as those in the spec, so in this sence the transition you mention, Nikhil, should be painless:

"Many people writing Web pages for the general public to access might want to use this flavor of XHTML 1.0. The idea is to take advantage of XHTML features including style sheets but nonetheless to make small adjustments to your markup for the benefit of those viewing your pages with older browsers which can't understand style sheets. These include using the body element with bgcolor, text and link attributes."

(via http://www.w3.org/MarkUp/)

Bertrand

Posted on 5/5/2005 @ 11:56 AM
Well, one thing that needs to be taken into account no matter how hard you want to push XHTML is that this is now the default *we* are forcing upon people, some of which were perfectly fine with the legacy rendering: it's not something that our users have explicitly chosen. So it's easy to say that these people should just get a grip and stop "developing like slobs", we *have* to make it painless for our existing customers to migrate to ASP.NET 2.0.
I agree that maintaining undocumented features is not something we're supposed to do, so this precise workaround is probably not absolutely necessary (and it adds some code that properly coded applications don't need), but the broader issue of maintaining back-compat still holds.

Sergio Pereira

Posted on 5/5/2005 @ 12:59 PM
Withou trying to make this comment thread longer than it should, I guess the problem is that XHTML is not backwards compatible with HTML 4.0. There's no straighforward upgrade path from one to the other. Providing an upgrade path will be more like equiping the patform with some hack.. well, clever hack with beautiful names, but hacks nonetheless.
Having that said, of course I want to move my apps to ASP.NET with a minimal number of changes, if any.

David

Posted on 5/8/2005 @ 11:14 AM
Xhtml 1.1 strict shouldn't even be considered cause the current versions of IE don't support it. Try it thru, Response.ContentType = "application/xhtml+xml";

I would like the switch between XHTML flavors to be set by the documents doctype. So if I have a HTML 4.01 Transitional doctype ASP.NET will pick up on it and the page will render by it and if I have a XHTML 1.0 Strict doctype the page will render by it and so on. And the default mode (XHTML 1.0 ***) should only be set when there are no doctype.
The discussion on this post has been closed. Please use my contact form to provide comments.