I have a testcase where I'm adding text to a document and then remove and re-add the documentElement, all in the onload handler. If I don't remove and re-add the document element, the scrollbars appear correctly if the content doesn't fit in the window, if I do remove and re-add they don't appear. While trying to make a better testcase I noticed that it seems to be important that the document doesn't need scrollbars before the onload handler runs and adds the content and that the replacing of the documentElement needs to happen in the onload handler too.
Created attachment 123329 [details] Testcase (no scrollbars)
Created attachment 123331 [details] Testcase (scrollbars)
This is the same old problem that we've hacked around before: http://lxr.mozilla.org/seamonkey/source/content/html/document/src/nsHTMLDocument.cpp#2436
It wouldn't surprise me if this is the result of someone mindlessly null-checking the result of GetParent rather than thinking about what to do if it's null. I've seen it happen before...
So... this worksforme on trunk, for whatever reason. No idea how to write a test for this, though.