0

I'm using fetch as seen here (Use fetch instead of ajax with redux-observable) to do a fetch on the server side with node. Unfortunately, AjaxObservable only works in the browser so I'm using isomorphic-fetch to do fetch on the server.

My code looks something like this:

            let fetch$ = null;
            if (canUseDOM) {
                fetch$ = AjaxObservable.create({
                    url,
                    method: 'GET',
                    responseType: 'json',
                    ...options
                }).takeUntil(action$.ofType(`${type}_CANCEL`));
            } else {
                fetch$ = Observable.from(fetch(url, options).then(response => {
                    return response.json()
                }).then(response => ({response})));
            }

            return fetch$
                .map(({response: payload}) => ({type, payload}))

However, when I run this on the server (i.e. canUseDOM == false), I get the following error:

RangeError: Maximum call stack size exceeded
at SafeSubscriber.Subscription.unsubscribe (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscription.js:79:19)
at SafeSubscriber.Subscriber.unsubscribe (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:122:38)
at SafeSubscriber.__tryOrUnsub (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:226:18)
at SafeSubscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:172:22)
at Subscriber._next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:125:26)
at Subscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:89:18)
at SwitchMapSubscriber.notifyNext (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/operator/switchMap.js:77:30)
at InnerSubscriber._next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/InnerSubscriber.js:23:21)
at InnerSubscriber.Subscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:89:18)
at MergeMapSubscriber.notifyNext (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/operator/mergeMap.js:85:30)
Community
  • 1
  • 1
Ben
  • 16,124
  • 22
  • 77
  • 122
  • Well, from the stack trace we can't see where the the Observable chain is called for the first time so it's hard to tell what even causes such recursion. – martin Nov 02 '16 at 17:11
  • Can you provide the entire code of your epic? – jayphelps Nov 03 '16 at 18:18

0 Answers0