You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it seems that I found a bug with turbo-stream handling promises resolving the same vlaue incorrectly.
I originally opened remix-run/remix#9466 but decided to dig a bit deeper and found the problem in this package.
In short, instead of the value of the second promise (resolving the same value) an empty array is returned like this:
The problem is, that on resolving the 2nd promise this check here does not add a new value to the response, as it was already returned with the first promise:
After looking through the code it seems to me, that we cannot reference previous values when unflattening the value of a promise.
Because of this my quick fix was to send the whole promise again, which is of course not optimal.
Hi,
it seems that I found a bug with turbo-stream handling promises resolving the same vlaue incorrectly.
I originally opened remix-run/remix#9466 but decided to dig a bit deeper and found the problem in this package.
In short, instead of the value of the second promise (resolving the same value) an empty array is returned like this:
Analysis
It seems to me, that flatten is used to flatten the initial array but also responses of resolved promises:
turbo-stream/src/turbo-stream.ts
Line 171 in a72f7a7
The problem is, that on resolving the 2nd promise this check here does not add a new value to the response, as it was already returned with the first promise:
turbo-stream/src/flatten.ts
Lines 24 to 25 in a72f7a7
The consequence is, that an empty array is returned here:
turbo-stream/src/turbo-stream.ts
Lines 177 to 184 in a72f7a7
This causes an error in the
unflatten
function which checks for an empty erray:turbo-stream/src/unflatten.ts
Line 35 in a72f7a7
Possible Fix
After looking through the code it seems to me, that we cannot reference previous values when unflattening the value of a promise.
Because of this my quick fix was to send the whole promise again, which is of course not optimal.
I opened a PR with a test case and a fix, see #29
Best, Vincent
The text was updated successfully, but these errors were encountered: