# RJS render errors when user clicks away before render completes

**URL:** <https://www.ruby-forum.com/t/rjs-render-errors-when-user-clicks-away-before-render-completes/171963>\
**Category:** Rails\
**Created:** [July 12, 2009, 12:10pm UTC](https://www.ruby-forum.com/t/rjs-render-errors-when-user-clicks-away-before-render-completes/171963 "2009-07-12T12:10:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rockrep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8baadc/32.png) [@rockrep](https://www.ruby-forum.com/u/rockrep)\
**Post date:** [July 12, 2009, 12:10pm UTC](https://www.ruby-forum.com/t/rjs-render-errors-when-user-clicks-away-before-render-completes/171963/1 "2009-07-12T12:10:24Z")

</div>

We have an issue where we are using RJS templates to render the  
results of Ajax calls. Everything works fine so long as the user  
waits for the render to occur. However, if the user initiates the  
request and the RJS template is still in the process of rendering, but  
hasn’t completed, and the user clicks a different link, then we get a  
Javascript alert popup “Unexpected Server Error” for each line of RJS  
that has not yet completed. There is no stacktrace in the  
development (or production) log. Once the alert(s) are cleared, the  
secondary request completes fine.

What is best practice for guarding against this situation, or at a  
minimum prevent the alert popup? We tried putting begin/rescue  
blocks around the RJS but that did not seem to help.

Any pointers appreciated.

Thanks,

Michale

---

<div class="post-metadata">

**Author:** ![rockrep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8baadc/32.png) [@rockrep](https://www.ruby-forum.com/u/rockrep)\
**Post date:** [July 12, 2009, 12:26pm UTC](https://www.ruby-forum.com/t/rjs-render-errors-when-user-clicks-away-before-render-completes/171963/2 "2009-07-12T12:26:12Z")

</div>

On Jul 12, 8:06 am, rockrep [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What is best practice for guarding against this situation, or at a  
> minimum prevent the alert popup? We tried putting begin/rescue  
> blocks around the RJS but that did not seem to help.

If the errors are javascript errors then it’s normal that trying to  
rescue things in the RJS did nothing: your rjs template just generates  
javascript that is executed by the browser at a later point in time.  
Have you tried using firebug (or similar) to work out what is actually  
happening?

Fred

---

<div class="post-metadata">

**Author:** ![rockrep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8baadc/32.png) [@rockrep](https://www.ruby-forum.com/u/rockrep)\
**Post date:** [July 13, 2009, 4:06am UTC](https://www.ruby-forum.com/t/rjs-render-errors-when-user-clicks-away-before-render-completes/171963/3 "2009-07-13T04:06:13Z")

</div>

Javascript errors happen all the time due to weird browsing behavior  
and usually go unnoticed by typical users (unless of course it’s being  
caused by your actual code). The fact that the error pops up in an  
alert window is a debugging feature of the Development environment in  
Rails. In other words, when your site is in Production mode on the  
server, the error should not trigger an alert window at all, and the  
error should generally go unnoticed by the user. And if they’re  
clicking to another page, then the error should have no effect on  
their browsing experience.

Unless of course you are getting these alerts in production mode, in  
which case that’s a whole other situation.

-Steve

---

<div class="post-metadata">

**Author:** ![rockrep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8baadc/32.png) [@rockrep](https://www.ruby-forum.com/u/rockrep)\
**Post date:** [July 28, 2009, 5:27am UTC](https://www.ruby-forum.com/t/rjs-render-errors-when-user-clicks-away-before-render-completes/171963/4 "2009-07-28T05:27:30Z")

</div>

> Unless of course you are getting these alerts in production mode, in  
> which case that’s a whole other situation.
> 
> -Steve

Fred and Steve. Many thanks for the replies. My apologies for not  
following up sooner but other priorities arose. I finally tracked  
this down to an alert thrown by our code. We were generating an  
alert when calling JQuery.ajaxSetup when handling the XMLHttpRequest  
Object UNSENT error status.

-Michael
