Aws-mobile-appsync-sdk-js: Server Side Rendering window is not defined

Created on 17 Jan 2018  路  10Comments  路  Source: awslabs/aws-mobile-appsync-sdk-js

I tried implementing SSR and it throws an error about the window not being defined. Looks like paho-client doesn鈥檛 support SSR.

All 10 comments

Hi @dav-is

Thanks for trying this SDK!

Can you try the code in Building a JavaScript Client App ?

Specifically, adding something like this for non-browser environments:

global.WebSocket = require('ws');
global.window = global.window || {
    setTimeout: setTimeout,
    clearTimeout: clearTimeout,
    WebSocket: global.WebSocket,
    ArrayBuffer: global.ArrayBuffer,
    addEventListener: function () { },
    navigator: { onLine: true }
};
global.localStorage = {
    store: {},
    getItem: function (key) {
        return this.store[key]
    },
    setItem: function (key, value) {
        this.store[key] = value
    },
    removeItem: function (key) {
        delete this.store[key]
    }
};
require('es6-promise').polyfill();
require('isomorphic-fetch');

I'm not able to find a way to setup global.window before importing aws-appsync in a next.js project.

Thoughts on using MQTT.js instead of Paho?

@dav-is, have you been able to accomplish anything on this issue?

@sakhmedbayev Honestly I dropped AWS Appsync in favor of Google鈥檚 cloud and just running a regular graphql server.

Hi!

We are actively working on removing dependencies on the window object to enable server side rendering without having to polyfill stuff. Stay tuned.

If you're curious how this would work in the future (please understand this is experimental and requires for now unpublished modules and unmerged pull requests to third party repos), you can take a look at manueliglesias/urban-pancake (a nextjs web app I am using to test stuff), specifically this piece https://github.com/manueliglesias/urban-pancake/blob/61f167f99793d6573adcf577d975578353d5b70c/lib/initApollo.js#L13-L31

Hi @manueliglesias, any progress or deadline on the server-sider version ? Thx

@growak @dav-is @cgarvis @sakhmedbayev we have a resolution however the dependent library that we use will not be updated until the end of next month. You can view the PR here. We are investigating ways to potentially get a published version sooner and talking to the contributors of that project. Please be patient as we work through the distribution process.

Why is this issue closed?

Any update on this, anyone manages to solve it somehow?

Was this page helpful?
0 / 5 - 0 ratings