New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflow is triggered when .data() is called in the options #4014
Comments
Hi guys, I faced the same problem these days. Any progress ? @kevin-brown @hacktivista |
@vin-zhou As workaround you can initialize parsley after select2. Eventually somebody will be able to fix the problem. I couldn't :( |
same here :( |
Here's an updated version of the jsfiddle that works out of the box, without any changes, to reproduce the issue that you appear to be seeing. http://jsfiddle.net/jew1mg89/5/ And it's true that initializing Select2 before initializing parsely will fix the issue, though I'm not sure why. |
Tracking this down a little further, the issue is triggered within You can reproduce the error without Select2 by trying to clone the data for an element using http://jsfiddle.net/jew1mg89/8/ I expected this to be an issue in Select2 as well, but apparently Select2 can be deep copied without issue. http://jsfiddle.net/jew1mg89/9/ So that officially makes this a Parsley issue, triggered by Select2. |
I feel that Can |
Note: I didn't check why |
This was added in a9f6d64 because we needed to normalize the result from Normally this isn't an issue because most plugins avoid circular references within their code, and instead store state like that in other areas. |
Thanks for the explanations. My impression now is that there's no need to call In particular:
So for example it would be possible that a library calls The fact is that |
Thanks for taking the time to look into this @marcandre as I really need a solution to this. |
You're right, Select2 could probably avoid calling One possible way might be to do a shallow copy of the data object, and then do a deeper copy of it if we can confirm that the value is not a complex JS object.
We're less concerned about that, but yes it is a possible issue one could encounter. We've seen (in the wild) that changes to
This is pretty much the only place in the code base which uses
This would be ideal, but Select2 (unlike parsley) does not have a small number of options. It actually doesn't have a fixed number of options that are used at any particular time, as adapters can specify new options that they are looking for. As you can imagine, this forces us to use a bit of magic to convert data attributes into options, resulting in what we currently have.
Just wanted to mention that we use |
Actually, parsley has an unlimited number of options too. We parse anything that starts with
Same with Parsley, actually. It's annoying that Would you like me to write something up for |
BTW, in your blog post, you write:
As I tried to explain before, this is incorrect. This can be quite confusing. In cases where the attribute is changed via JS, a reading call to |
+1 |
@kevin-brown what is your last word on this, or have you not yet decided? |
My tentative plan is to rewrite how we clone the field-level data to exclude anything that wouldn't normally come from jQuery or the DOM. It'd be slightly easier if Select2 had a prefix for the data attributes, but that's a mistake we are going to have to live with. In any case, I'm going to reopen this ticket and give it a more relevant title. |
+1 |
+1 |
#4346 has been merged into |
Possibly Bug: I was migrating from Select2 4.0.3 to Select2 4.0.6-rc.1, I have noticed that it has stopped taking effects of data-attributes like placeholder, minimum-input-length, ajax--delay etc mentioned in element html. Same bug continues to latest RC.1 Steps to reproduce:
This will not show placeholder, will not consider min length or delay JS Fiddle(Select2 4.0.5): https://jsfiddle.net/gyf7fkmo/2/ Resolution: Reverting to $.data resolves the problem. |
There was a change made that switched us from using `$.data` and `$.fn.data` internally to using an internal data store (managed through internal utilities). This had the unfortunate side effect of breaking the automatic loading of data-* options in versions of jQuery other than 1.x, which included anything that would be considered modern jQuery. While the change was made and approved in good faith, all of the tests passed and the docs pages appeared to be working, the tests really failed when running on newer versions of jQuery. This was confirmed when we started running automated tests against both versions, which confirmed the bug that others have been seeing for a while. The change was made becuase calling `$.fn.data` on an element which contains a reference to itself in the internal jQuery data cache would cause a stack overflow. This bug was well documented at the following GitHub ticket and was resolved by no longer using `$.fn.data`: #4014 Unfortunately because `$.fn.data` was no longer being called in a way such that all of the data attributes would be dumped out, we needed to find a replacement. The substitute that was given in the original bug fix worked when the data cache was fully primed, but we never primed it anywhere so it actually failed in the general case. That meant we needed to find a way to manually prime it, which is exactly what this change does.
* Start running tests against jQuery 2.x We were only running tests against jQuery 1.x before and they were all passing. This was a problem because apparently all of the data-* attribute tests fail in jQuery 2.x. We are now running both the integration and unit tests against both jQuery 1.x and jQuery 2.x. Right now this resulted in a complete duplication of the test files because there wasn't an obvious way to run the tests against both versions. We're going to look into removing this duplication in the future once the current issues are fixed. We are also going to look into testing against jQuery 3.x in the future, since that is also a supported line of jQuery. * Force the data-* attributes to be parsed There was a change made that switched us from using `$.data` and `$.fn.data` internally to using an internal data store (managed through internal utilities). This had the unfortunate side effect of breaking the automatic loading of data-* options in versions of jQuery other than 1.x, which included anything that would be considered modern jQuery. While the change was made and approved in good faith, all of the tests passed and the docs pages appeared to be working, the tests really failed when running on newer versions of jQuery. This was confirmed when we started running automated tests against both versions, which confirmed the bug that others have been seeing for a while. The change was made becuase calling `$.fn.data` on an element which contains a reference to itself in the internal jQuery data cache would cause a stack overflow. This bug was well documented at the following GitHub ticket and was resolved by no longer using `$.fn.data`: #4014 Unfortunately because `$.fn.data` was no longer being called in a way such that all of the data attributes would be dumped out, we needed to find a replacement. The substitute that was given in the original bug fix worked when the data cache was fully primed, but we never primed it anywhere so it actually failed in the general case. That meant we needed to find a way to manually prime it, which is exactly what this change does. * Clean up select2/utils
I can't reproduce your issue in 4.0.10, see https://jsfiddle.net/javier_tejero/vm7a94pL/ |
I don't know if it's a Select2 problem, or a Parsley problem. I couldn't identify the error :(
Here is the simplest fiddle which shows the problem:
http://jsfiddle.net/jew1mg89/1/
The error is not present using the previous version of Select2 (3.x)
The text was updated successfully, but these errors were encountered: