canjs / can-zone

A context for tracking asynchronous activity in JavaScript applications.
https://v4.canjs.com/doc/can-zone.html
MIT License
92 stars 4 forks source link

WebSocket messages do not occur with a Zone #108

Open matthewp opened 7 years ago

matthewp commented 7 years ago
ws.onmessage = function(){

};

If some behavior is completed within a websocket message this needs to be wrapped within the Zone.

frank-dspeed commented 7 years ago

is this the bug https://github.com/feathersjs/feathers-socketio/issues/81

they say zones can't handle socket.io in general.

matthewp commented 7 years ago

Yep, this is true.

frank-dspeed commented 7 years ago

as far as i understand For can-zone to work we have to override various task-creating functionality, this is the list of what we currently implement:

Macrotasks

setTimeout XMLHttpRequest Microtasks

requestAnimationFrame Promise process.nextTick

we need to implament socket.io here or i use a promis based socket io lib?

matthewp commented 7 years ago

I think the socket.io issue is because they do a recursive setTimeout. Without some heuristic to detect this I'm not sure that's fixable.

matthewp commented 7 years ago

Yes, using Zone.ignore will ignore any async tasks that are called within.

frank-dspeed commented 7 years ago

Current Workaround is

  1. rendering head and body stache directly to html and disable done-autorender

    • pro: it works without SSR
    • con: Don't works with SSR
  2. Use done-autorender without zones

  3. use ignore Prototype from can-zone The issue is Zone related. The reason it is not rendering is because the Zone never completes and done-autorender waits for the Zone to complete. You can use Zone.ignore to ignore functions:

    
    var Zone = require("can-zone");
    var someFunctionThatCallsSetInterval = require("dep");

var ignored = Zone.ignore(someFunctionThatCallsSetInterval);

// Now you can safely call ignored() ignored()