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

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

Open
marshallswain opened this issue Nov 10, 2016 · 2 comments
Open
Assignees

Comments

@marshallswain
Copy link
Member

marshallswain commented Nov 10, 2016

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.
@BigAB BigAB added the p2 label Nov 11, 2016
@marshallswain marshallswain changed the title steal-socket.io client needs to read from the XHR_CACHE Make a feathers-ssr behavior that switches between socket/XHR Nov 29, 2016
@marshallswain
Copy link
Member Author

Notes from the meeting.

feathersClient - maintained independently

  • can-connect-feathers - light weight wrapper, simlar to SignalR
    • getListData, getData -> feathersClient
    • createInstance

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 marshallswain changed the title Make a feathers-ssr behavior that switches between socket/XHR Make a feathers-ssr behavior that switches between sockets/XHR Nov 29, 2016
@marshallswain marshallswain self-assigned this Nov 29, 2016
@marshallswain
Copy link
Member Author

This won't be necessary if donejs/done-ssr#198 happens.

@justinbmeyer justinbmeyer removed the p2 label Dec 16, 2016
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

No branches or pull requests

3 participants