Closed kingRayhan closed 2 years ago
Are you using a framework like NextJS by chance?
@alamorre I am having the same issue, and yes I am using NextJS
i have the same problem , i am using reactJs
@alamorre I am having the same issue, and yes I am using NextJS
Hi . did you solve it
Not yet I have a lot on my plate and this requires building a whole next js specific dependancy๏ฟผ.
Additionally people with pro plans have roadmap influence so anybody that needs next JS on pro can make it happen this month ๐๐ผ๏ฟผ
This appears to be an issue directly with the way Quill.js publishes their css imports to npm. And given they have over a 1,000 issues with little to no response on almost all of those issues, I don't forsee them making any changes anytime soon. Unfortunately this blocks me from being able to use this as Next.js is crucial for what I am building. I understand other priorities but a big plus one from me on this as I can't use the library until this is fixed.
That being said, this looks to be a fairly common issue people have when working with Next, so I'll dive in and see if I can find a fix.
There is an easy fix. I exclude that css import and you pull it in yourself. I can make a nextjs compatible verion of chat engine tofay
Hey everybody ๐ Simple hack, but I put together nextjs-chat-engine
It's a workaround where you pull in the component then import require('react-quill/dist/quill.snow.css');
separately.
Please let me know if this helps y'all out, enjoy ๐
Has anybody tried this out yet? I want to see if it helped out
Has anybody tried this out yet? I want to see if it helped out
I'll give this a shot today! Thanks for putting it together
Has anybody tried this out yet? I want to see if it helped out
Hey @alamorre, I give it a try and it's fixing the mentioned issue with the styling. Unfortunately it shows another issue:
ReferenceError: document is not defined
I am using only nextjs-chat-engine
and I added the ChatEngine
component in a page component in Next.
import { ChatEngine, getOrCreateChat } from 'nextjs-chat-engine';
const Chat = () => {
return (
<ChatEngine
projectID='xxxxxx'
userName='Val'
userSecret='pass'
/>
)
}
Any recommendations?
I investigated more and found out that the issue is coming from the react-quill
library. I manage to fix it by using dynamic import for it in nextjs-chat-engine
package. More info here: https://github.com/zenoamaro/react-quill/issues/718#issuecomment-856755998
and refactoring my component with the loading "hack":
const Chat = () => {
const [loading, setLoading] = useState(true)
useEffect(() => {
setLoading(false)
}, [])
if (loading) {
return (
<div>
Loading...
</div>
)
}
return (
<ChatEngine
projectID='xxxxxxx'
userName='Val'
userSecret='pass'
/>
)
}
I am happy to create a PR in nextjs-chat-engine
and probably the docs needs updating if this is the way to go ^.
Awesome ๐๐ฝ yeah if you make a PR in nextjs chat engine I'll definitely approve it.
Also can you please add to the readme any steps you need to take for it to work normally? You're awesome ๐คฉ
Cheers for this, waiting for the PR to be approved and merged with a readme update. Y'all are awesome
@alamorre Using @ValGeorgiev solution, I got everything working on my end!
Hey everybody, just a heads up I'm learning NextJS now and plan on supporting it formally this month ๐ ๐
Hey how did you do the dynamic import on react-chat-engine
I used the code below and it's not working. Also, all sub-components are undefined ๐
const ReactChatEngine = dynamic(() => import('react-chat-engine'), { ssr: false })
console.log('ReactChatEngine', ReactChatEngine) // odd object
console.log('ReactChatEngine', ReactChatEngine.ChatEngineWrapper) // undefined
console.log('ReactChatEngine', ReactChatEngine.ChatHeader) // undefined
console.log('ReactChatEngine', ReactChatEngine.ChatFeed) // undefined
Interesting, this works:
const ChatEngineWrapper = dynamic(() => import('react-chat-engine').then((module) => module.ChatEngineWrapper));
const ChatSocket = dynamic(() => import('react-chat-engine').then((module) => module.ChatSocket));
const ChatHeader = dynamic(() => import('react-chat-engine').then((module) => module.ChatHeader));
const ChatFeed = dynamic(() => import('react-chat-engine').then((module) => module.ChatFeed));
I'll add this to the docs and update it all tmo. PS I fixed it on react-chat-engine so nextjs-chat-engine
will become deprecated
Okay, so sounds like we are all good here pending the PR for the fix being pushed? I've got it all working on my end.
Here is a post addressing everything and how it works now ๐