-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Bugfix/query param serialization #19145
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Can we prevent the double encoding from happening to begin with?
I'd love to hear how to prevent the double encoding 😄 |
Well, in general, ember.js/packages/@ember/-internals/routing/lib/system/route.ts Lines 2555 to 2557 in 15217a3
Assuming that is the case, it would infer that the controller's local property representing the QP is actually changing from an array to a string (for some period of time). Where is that happening? |
@mfeckie - Any chance to look into that? |
@rwjblue Sure, will do some digging :) |
After many hours of digging today, I think it's because of this ember.js/packages/@ember/-internals/routing/lib/system/router.ts Lines 1621 to 1638 in 15217a3
ember.js/packages/@ember/-internals/routing/lib/system/router.ts Lines 1633 to 1636 in 15217a3
This isn't a 'problem' when a full cycle completes, I think, because When additional changes happen (e.g. user adds more characters to search) serialize ends up being called multiple times and deserialize doesn't get called the same number of times. At this point, I can say that the proposed fix does work, but I can't say that this investigation left me feeling like I truly know what's going on. |
No, I didn't. I opened this PR back in September and haven't been keeping track of changes |
We should still try to land these tests, even if the other PR fixed the underlying issue. |
@rwjblue Why should we support query parameters serialized multiple times? |
@mfeckie @rreckonerr From what I see, the
loop. That beeing said, since the underlying issue is fixed, this case should not happen. Or maybe I miss something. cc/ @rwjblue |
@rwjblue Perhaps this one is not necessary., see #15611 (comment) |
When Ember serializes a query parameter of type
Array
, it does so with JSON.stringify.Deserialize converts the
string
back to anArray
.If there are slow / high latency network connections, it is possible for the
serialize
method to get called in rapid succesion, prior todeserialize
being called. This results inJSON.stringify
being called multiple times on the value, which results in to being converted from anArray
to astring
I've put together a reproduction over on ember-twiddle. note if you try too hard, it may crash the browser because the strings grow exponentially.
I've added failing tests for this scenario and then implemented a fix.
I have added a
while
loop to recursively deal with scenarios where the QP's may have been repeatedly encoded. I don't think this could result in an infinite loop, rather it would result in a error breaking the loop.