Note that there are some explanatory texts on larger screens.

plurals
  1. POExtJs exceptions immediately break all ExtJs components on a page
    primarykey
    data
    text
    <p>If you've ever worked with ExtJs, you've probably run into the nefarious "Cannot read property 'dom' of null" exception. For me, it usually happens inside doInsert (the last of 14 stacks in the outer trace) (ExtJs's code):</p> <pre><code>doInsert: function(el, o, returnElement, pos, sibling, append) { //&lt;My own comment&gt;: hint: el === null (curiously not undefined?) el = el.dom || Ext.getDom(el); var newNode; ... } </code></pre> <p>This happens when you attempt to attach an ExtJs component (Tree, Grid, Button, whatever) to a DOM element which is not yet in the DOM. Usually the element is in memory, constructed as part of an AJAX request, ready to be inserted on success.</p> <p>The problem is that when ExtJS throws, <strong>it fundamentally breaks every ExtJs component in the page</strong>. All grids, trees, menus, buttons are immediately mangled. Event bindings like click and hover either do nothing or generate exceptions.</p> <p>I currently mitigate against this by first doing a document.getElementById check, and if the result is undefined, then I defer 100 ms and try again. This is ugly, but it works. It's also expensive to do. As certain pages get more complex, that's more and more document.getElementById defer loops; and it gets harder and harder to track down which method inside which module hasn't tested getElementById.</p> <p>It's a mess.</p> <p>Question: is there any way to force ExtJS to throw gracefully? To override its exception handling mechanism? Flip the "dontBreakTheEntirePage" configuration variable?</p> <p><strong>UPDATE</strong>:</p> <p>After trying to go <a href="http://www.sencha.com/forum/showthread.php?263283-ExtJs-exceptions-immediately-break-all-ExtJs-components-on-a-page" rel="nofollow">direct to Sencha and after a few rebuffs</a>, I demonstrated the problem more clearly (I hope):</p> <p><strong>EDIT</strong>: Sencha is moderating my replies to the <a href="http://www.sencha.com/forum/showthread.php?263283-ExtJs-exceptions-immediately-break-all-ExtJs-components-on-a-page" rel="nofollow">original thread</a>. If you have any interest in this class of fault, please add to the discussion.</p> <ol> <li>Open the docs (<a href="http://docs.sencha.com/extjs/4.1.0/" rel="nofollow">http://docs.sencha.com/extjs/4.1.0/</a>)</li> <li>Open a few tabs (I have Ext, Ext.tree.Panel, Ext.menu.Menu, Ext.AbstractComponent, and Ext.draw.Color)</li> <li>Open the Chrome Dev Tools and look for errors.</li> <li>Click back and forth between tabs a few times as a sanity check. Tabs render as expected, without error.</li> <li>Now, let's break the page.</li> <li>Back to the Dev Tools.</li> <li>Switch to the console.</li> <li><p>Define an adhoc method: </p> <pre><code>var tryCatch = function (func) { try { func.apply(this, Array.prototype.slice.call(arguments, 1)); } catch (ex) { var e = { type: 'js', message: ex.message, detail: 'JS Error type: ' + ex.type + '&lt;br/&gt;\n' + 'Stack: ' + ex.stack }; console.error(e); } }; </code></pre></li> <li><p>Define a method which will throw an exception: </p> <pre><code>var myExceptionFunction = function () { //Demo taken straight from ExtJs docs on Ext.menu.Menu Ext.create('Ext.menu.Menu', { width: 100, margin: '0 0 10 0', floating: false, renderTo: 'thisIdDoesNotExist', //and will break the already rendered page items: [{ text: 'regular item 1' }, { text: 'regular item 2' }, { text: 'regular item 3' }] }); }; </code></pre></li> <li><p>Execute the myExceptionFunction method in the tryCatch wrapper: </p> <pre><code>tryCatch(myExceptionFunction); </code></pre></li> <li><p>Observe the reported error: "Cannot read property 'dom' of null"</p></li> <li><p>Now start clicking back and forth between the opened tabs.</p></li> <li><p>Suddenly, the page is exhibiting some odd behavior.</p></li> <li><p>You begin to see new exceptions in the console: "Uncaught TypeError: Cannot read property 'dom' of undefined" Tabs render, but in unexpected places. The currently selected tab is not always properly updated.</p></li> </ol> <p>Now, ExtJs's documentation site actually handles this fault quite well. Most of the page still works in ways that you can cope with; but in my scenario, my page is crippled.</p> <p>We're talking about content that has already rendered--is already in the DOM. I cannot imagine a reason for exceptions thrown past that point to break what has already executed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload