← Back to team overview

mahara-contributors team mailing list archive

[Bug 1544424] Re: Endless JS loop if there's an uncaught exception in an ajax block

 

** Changed in: mahara/15.10
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.
Matching subscriptions: Subscription for all Mahara Contributors -- please ask on #mahara-dev or mahara.org forum before editing or unsubscribing it!
https://bugs.launchpad.net/bugs/1544424

Title:
  Endless JS loop if there's an uncaught exception in an ajax block

Status in Mahara:
  Fix Committed
Status in Mahara 15.10 series:
  Fix Released
Status in Mahara 16.04 series:
  Fix Committed

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_instance()", it returns a placeholder with some data attributes that identify it as an ajax block placeholder, and indicate which block instance to load there.
  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.ajax.php?block_instance=X" for each one, and then takes the return value from that request and pops it into the page, also triggering any Javascript that is loaded in that return value.
  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->handle_exception() method, which loads up error.tpl in order to display a nice error page with the standard headers and footers.
  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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/mahara/+bug/1544424/+subscriptions


References