enonic / nextxp-demo

Apache License 2.0
2 stars 17 forks source link

The hotreloading does not work inside xp #327

Open poi33 opened 2 years ago

poi33 commented 2 years ago

When you are in devmode and update a page the page is not updated. This works if you directly access the next frontend server (default port: 3000) So probably an issue in the next proxy?

poi33 commented 2 years ago
Firefox can’t establish a connection to the server at ws://localhost:8080/admin/site/preview/project/draft/sitename/_next/webpack-hmr. [main.js:36:17](http://localhost:8080/admin/site/preview/company-web/draft/sitename/_next/static/chunks/main.js?ts=1657278989876%20line%2071%20%3E%20eval)
GETws://localhost:8080/admin/site/preview/project/draft/site-name/_next/webpack-hmr
pmi commented 2 years ago

When used directly at localhost:3000 nextjs client-side code creates a websocket connection at /_next/webpack-hmr. When used in XP /_next/webpack-hmr is transformed to /admin/site/inline/next/draft/hmdb/_next/webpack-hmr. So the websocket connection should be handled by lib-nextjs-proxy now, and tunneled to localhost:3000/_next/webpack-hmr.

The main problem here is that lib-http-client that we use in lib-nextjs-proxy is not able to handle ws requests. So even though there is a websocket XP lib that can be used to allow ws connection from browser to lib-nextjs-proxy, we won't be able to forward it to the next server.

So we either can try to leave this url out of url rewriting and let it connect directly to nextjs server bypassing the lib-nextjs-proxy. Or we can disable hot reload when viewed in XP completely, but keep it on when viewed directly on localhost:3000.

poi33 commented 2 years ago

I don't mind tunneling it dirrectly to localhost:3000 since this would only be done on development servers. But it is a bit annoying for developers to have to setup different connections for ws and another one for other traffic.

I see two options here:

  1. Make a feature request to handle websockets in http-lib with our use case
  2. Bypass to localhost:3000 and consider this as an okay way to do it.