Endless JS loop if there's an uncaught exception in an ajax block
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mahara |
Fix Released
|
Medium
|
Aaron Wells | ||
15.10 |
Fix Released
|
Medium
|
Aaron Wells |
Bug Description
I noticed this one via Bug 1544381. If there is a Dwoo error in one of the blocks rendered via Ajax, then it causes an endless loop of Javascript. To the end user, the appearance is that the title bar of the page keeps flashing, and the browser slows down somewhat.
What's happening is this:
1. The initial call to view.php tries to render every block.
2. For the ajax blocks instead of calling "render_
3. view.php's template loads up "head.tpl", which is hard-coded to include "block.js", the Javascript file with the code to load the AJAX blocks.
4. block.js, once it's loaded, executes some code that finds every one of those ajax block placeholders, executes "blocktype.
5. blocktype.ajax.php calls render_instance() on the block instance that has been passed to it.
6. If render_instance() triggers an uncaught MaharaException, then it gets handled by the MaharaException
7. error.tpl includes head.tpl, which then includes "block.js" again.
8. block.js again locates every AJAX block and calls blocktype.ajax.php and loads its content again. It scans the whole page, which mean it notices and re-executes for the AJAX blocks from the initial view.php call!
9. The block errors out again.
10. The new error again loads error.tpl
11. error.tpl again includes block.js
12. block.js again locates every AJAX block...
This problem is present in 15.10+. It was caused during the Bootstrapification, when we rewrote the ajax block code to remove the executable code from each block and put it all into block.js. The simplest solution is probably just to make sure that block.js only gets included in pages where it is actually needed. (Also, possibly, to put a check into block.js to make sure it only gets executed *once* per pageload, even if it is loaded multiple times. Perhaps using a Javascript variable in global scope.
tags: | added: ajax bootstrap javascript regression |
no longer affects: | mahara/16.04 |
Changed in mahara: | |
status: | Fix Committed → Fix Released |
Patch for "master" branch: https:/ /reviews. mahara. org/6055