react-livechat icon indicating copy to clipboard operation
react-livechat copied to clipboard

Incompatible with SSR

Open emirotin opened this issue 7 years ago • 4 comments

Related to https://github.com/livechat/react-livechat/issues/19 This component is using componentWillMount hook which is a) deprecated and b) apparently called in Next.js server-side rendering

Switching to componentDidMount would fix this in my understanding. I can send a PR but this repo doesn't have the rollup config file so I cannot test the builds when iterating on the code.

If you'd publish your rollup.config.js and maybe other dev-related stuff I'd send a PR myself.

emirotin avatar Mar 01 '19 12:03 emirotin

Just figured I have the same problem here

benb1983 avatar Jan 06 '20 09:01 benb1983

this worked for me

import React from 'react';
import LiveChat from 'react-livechat'

export default class LiveChatApi extends React.Component {
	render() {
		if (typeof window === 'undefined') return null;

		return (
			<LiveChat license={11794446} />
		);
	}
}

nesbtesh avatar May 30 '20 00:05 nesbtesh

Yes, of course, there are workarounds. Still, this component could (and should) be improved if only LC didn't forget about this repo.


BTW, your code can be even shortened:

import React from 'react';
import LiveChat from 'react-livechat';

export default const LiveChatApi = (props) =>
  typeof window !== 'undefined' && <LiveChat {...props} />

emirotin avatar May 30 '20 09:05 emirotin

Hello 👋

We didn't forget fortunately 😅 I am happy to say that we have created a new set of packages to support more frontend frameworks integration with LiveChat Chat Widget: Chat Widget Adapters.

After the first main implementation, we are planning to introduce support for SSR and SSG. You can feel free to open feature request or send us an issue report 🙂

walaszczykm avatar Jan 23 '22 13:01 walaszczykm