donejs / bitcentive

https://bitcentive.herokuapp.com/
MIT License
7 stars 3 forks source link

Make a feathers-ssr behavior that switches between sockets/XHR #97

Open marshallswain opened 7 years ago

marshallswain commented 7 years ago

XHR requests made by the SSR server get stored in the XHR_CACHE. The socket.io client isn't aware of it, so it makes the same requests again instead of using the cached ones.

Based on the meeting notes in the next comment, we need to make a behavior specifically for SSR that...

  1. Uses XHR requests on the server. The existing CanZone plugin for handling XHRs will populate the XHR_CACHE.
  2. Uses XHR requests on the client before re-attachment of the client app to the SSR-rendered DOM. These XHR requests will check the XHR_CACHE.
  3. Allows the client to fall through to using another behavior (in our case the feathers behavior) on the client AFTER re-attachment.
marshallswain commented 7 years ago

Notes from the meeting.

feathersClient - maintained independently

Making re-attachment work

1. Socket.io on the server / low level

Problems:
    - it slow 
    - statefully authenticated.  
        cookie -> 
            socket.emit("authenticate", {token: cooke.read("token")})
    - one socket for every incoming SSR request.  We'd have to make a new one for each.
        - share approach 
        - socket = io()
            socket.emit() =>
                var socket = io()
                socket.emit()
    - socket.io shim ... underneath socket.emit
        - if it were a global ... we could 
            var XHR = XMLHTTPRequest;
            getList : function(){
                new XHR()
            }
Benefit:
    - anything works 

2. can-connect-server-side-rendering

    var ssrConnection = connect(["data-url"],{
        url: "/api/todos"
    })

    Todo.connection = connect(["can-connect-ssr","feathers-socket.io"],{
        serverSideConnection: ssrConnection,
        Map: Todo
    });

    behavior("can-connect-ssr",function(baseConnection){
        getListData: function(){
            if(!Zone.re-attached || isNode) {
                return this.serverSideConnection.getListData.apply(this.serverSideConnection, arguments);
            } else {
                baseConnection.getListData({})
            }
        }
    })
marshallswain commented 7 years ago

This won't be necessary if https://github.com/donejs/done-ssr/issues/198 happens.