Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
preserve-inputs conflicts with #constant #1301
This is an example of a constant region which is no longer constant when the preserve-inputs packages is used. It looks like if the constant region contains an input element with an id (one of the things that preserve-inputs tries to preserve), the constant region is no longer constant (it gets fixed up, instead of only being added or removed as a whole). preserve-inputs shouldn't affect constant regions.
(The unnamed collection N is used here instead of a simple Session variable to store the incrementing number because doing that triggers another variant of the bug, see below).
Run this without preserve-inputs, and it works correctly: "adding stuff" is printed once at startup. Clicking the button increments the displayed number, but "adding stuff" isn't displayed again. (Without the constant region it would be because the template would get re-rendered, removing the added "stuff" div).
Now add preserve-inputs. This time the #constant region is no longer constant: click the button, and "adding stuff" is printed again.
This turns out to be especially bad with jQuery plugins that attach some data to an element as an indicator that the plugin has initialized. Because the data is still there attached to the input element, the plugin thinks that it has been initialized (which is was), but the plugin gets confused because the extra elements it added are missing.
In summary, a constant region should only be added or removed as a whole, it shouldn't be modified on re-render. preserve-inputs doesn't need to go into constant regions.
Fun variants (with preserve-inputs included), probably related to the same bug:
Move the button into the "hello" template. After clicking the button once, the button event handler is no longer called when the button is clicked again.
Rather than using "#with" and a unnamed collection, use a simple Session variable instead:
and have the button increment n. Now