This project is archived and is in readonly mode.

UJS & partial possible bug
Reported by Philippe Lang | September 22nd, 2010 @ 10:33 AM
Hi,
I'm new to rails, so this might be my fault instead of a bug. But at least it sounds odd. Here are a few files:
list.html.erb
<table>
<% @boxes.each do |box| %>
  <tr>
    <td><%= box.name %></td>
  </tr>
<% end %>
</table>
<div id="add">
  <%=
    render :partial => "list_add"
  %>
</div>
_list_add.html.erb
<%=
  link_to_function("add a new box") do |page|
    page.replace_html "add", :partial => "list_new"
  end
%>
_list_new.html.erb
<%=
  link_to_function("finished adding a new box") do |page|
    page.replace_html "add", ":partial => list_add"
  end
%>
This code crashes the WEBrick server when trying to render list.html.erb:
macbook-pro-de-philippe-lang:attikdb plang$ rails s
=> Booting WEBrick
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-09-22 11:09:56] INFO  WEBrick 1.3.1
[2010-09-22 11:09:56] INFO  ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0]
[2010-09-22 11:09:56] INFO  WEBrick::HTTPServer#start: pid=2959 port=3000
Illegal instruction
macbook-pro-de-philippe-lang:attikdb plang$
Browser says:
Erreur 324 (net::ERR_EMPTY_RESPONSE) : Erreur inconnue
A small change and the server does not crash anymore:
_list_new.html.erb
<%=
  link_to_function("finished adding a new box") do |page|
    page.replace_html "add", "rendering list_add partial here..."
  end
%>
It looks like rails does not like partials rendering each other through UJS.
What I'm trying to acomplish here is some kind of web 2.0 in-place editing at the bottom of a list. There might be a better way of doing that, sure!
My config: ruby 1.9.2, rails 3.0.0
Comments and changes to this ticket
- 
            
         Marjan Krekoten' September 22nd, 2010 @ 09:44 PMWell I maybe wrong but your code just enters infinite loop. _list_add.html.erband_list_new.html.erbrender each other until ruby crashes.
- 
            
         Philippe Lang September 23rd, 2010 @ 07:04 AM- Tag changed from illegal response, partial, ujs to illegal instruction, partial, ujs
 Hi Marjan, Each partial renders the other, but only after a click, since "link_to_function" is used. This shouldn't be a problem as far as I understand. But you are right, there must be some kind of infinite loop inside the framework. 
- 
            
         Marjan Krekoten' September 23rd, 2010 @ 07:11 AMIt renders partials on server side. JS code on clients side operates with already rendered strings. So while rendering those partials are trying to render each other. 
- 
            
         Philippe Lang September 23rd, 2010 @ 07:21 AMWhen rendering list.html.erb, I thought that only the _list_add.html.erb partial was rendered, with a link allowing the rendering of the next partial through UJS, and so on. Conceptually, I have to admit I still don't see exactly why this code breaks... 
- 
            
         Philippe Lang September 23rd, 2010 @ 08:50 AMHum, I think I understand better now. As you say "JS code on clients side operates with already rendered strings". That means rails tries to pre-render both partials rendering each other, UJS or not, resulting in an infinite loop. I could see that with a few puts added at the top of the partials: ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new ------> rendering add ------> rendering new Illegal instructionSo I guess this is not a bug at all: rails certainly works like this "by design". 
- 
         David Trasbo September 25th, 2010 @ 06:18 PM- State changed from new to invalid
- Importance changed from  to Low
 See above. 
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
 David Trasbo
      David Trasbo
 Jeremy Kemper
      Jeremy Kemper