Skip to content
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

Comet, Comet on the Wall: Fix comets sent down via AJAX from within a comet #1646

Merged
merged 5 commits into from
Jan 15, 2015

Conversation

Shadowfiend
Copy link
Member

This fixes a few issues:

  • We centralize comet command generation into S.jsToAppend.
  • We fix when we look up S.jsToAppend during AJAX processing in comet contexts so we don't miss anything that might be added during the actual AJAX function execution.
  • We make sure not to trigger a second comet request when setting up new comets client-side from within a comet response.

Fixes issue #1645 .

We do this because jsToAppend is referenced in a few
different places, and it’s better to reuse it than to try and add
commandForComets to all of those places (especially since
some of them are inside CometActors, for example).
When dealing with an AJAX request in a comet context, we
were partial-updating jsToAppend at the beginning of the
request, but any updates that might have been made to it
during the request processing were lost. We now send the
partial update message after the request functions have run,
so that any JS they’ve appended also gets sent down to the
client.
If a comet was sent down from within a comet context, we
would force a comet request reset. On the client, this would
schedule a new comet request and attempt to abort the old
one; however, there is no way to abort the old one, since its
success handler is what is kicking off this request reset.

The end result is that the request’s success handler finished
running, which would also schedule a new comet request,
and we’d get two comet requests running in parallel and
walking all over each other.

When generating the comet commands, we now check to
see if we’re executing in a comet context, and if we are we
ask the client not to reset the comet cycle, knowing that the
response we’re currently sending will immediately kick off a
new request once it’s done executing.
We now pull jsToAppend handling out of the message
handler for comet-context AJAX request processing all the
way to the wrapper around handling all messages. This
ensures that things like partial updates will properly render
their JS to append.

It also seems to incidentally fix S.jsToAppend within comet
rendering, which seemed to trigger the JS twice instead of
just once before this.
S.jsToAppend() match {
case Nil =>
case js => partialUpdate(js)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern here is this, which was originally added to deal with some race conditions with wiring, I believe. I don't think what we're doing now will be significantly different, since the fact that it's a partialUpdate in both cases means it will be processed as a subsequent message to the comet in both cases, but it's worth pointing out in case anyone disagrees.

@Shadowfiend
Copy link
Member Author

Thoughts on this?

@andreak
Copy link
Member

andreak commented Dec 22, 2014

I haven't gotten a chance to test this but is this supposed to fix the issue where using wiring from within a lazy-loaded snippet (added using AJAX) doesn't work?

@Shadowfiend
Copy link
Member Author

It may fix that… But it may not. This fixes issues with sending comets down from within AJAX requests that are bound within other comets, amongst other things. It would also fix any other issues with jsToAppend within comets. Since lazy loading uses comets, and I believe Wiring uses appendJs, it could conceivably fix the issue you're describing. I don't use Wiring, so I'm not sure.

In general, it fixes most uses of jsToAppend within a comet context, which until now only worked occasionally and in some cases triggered double execution.

The original issue that caused me to investigate and fix is on the mailing list.

@Shadowfiend
Copy link
Member Author

Worth mentioning, https://github.com/gvdm/lift-multi-chat can be used to see the intended fix.

case Nil => Empty
case x :: Nil => Full(x)
case xs => Full(xs.reduceLeft(_ & _))
protected implicit def nsToNsFuncToRenderOut(f: NodeSeq => NodeSeq) = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance of us renaming this to nodeSeqFuncToRenderOut?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And changing f to something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe as part of some future cleanup pass. Though tbh nodeSeqFunc isn't quite right (this is specifically NodeSeq to NodeSeq) and the difference is small enough, especially when tucked into an implicit which will never be explicitly invoked, that it's not really a big deal IMO.

@Shadowfiend Shadowfiend added this to the 3.0-M3 milestone Jan 7, 2015
@Shadowfiend
Copy link
Member Author

K, fixed the one style thing I wanted to fix before this went in. Going to send it in tomorrow (hopefully heh) if nothing else comes up.

@Shadowfiend
Copy link
Member Author

Lighting this green.

Shadowfiend added a commit that referenced this pull request Jan 15, 2015
Comet, Comet on the Wall: Fix comets sent down via AJAX from within a comet

This fixes a few issues:

 - We centralize comet command generation into S.jsToAppend.
 - We fix when we look up S.jsToAppend during AJAX processing in comet contexts
   so we don't miss anything that might be added during the actual AJAX function execution.
 - We make sure not to trigger a second comet request when setting up new comets
   client-side from within a comet response.
@Shadowfiend Shadowfiend merged commit cbc63a1 into master Jan 15, 2015
@Shadowfiend Shadowfiend deleted the comet-comet-on-the-wall branch January 15, 2015 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants