Open jordanmnunez opened 2 years ago
Hi.
I'm experiencing the same thing with a brand new setup of Next 13.
We have a very similar setup to @jordanmnunez with per-developer root domains and assetPrefix
set up.
Our current workaround is to use environment variables to determine if we're running in dev
mode and then set the assetPrefix
with domain included. To extend on @jordanmnunez example, this would be:
assetPrefix: process.env.NODE_ENV === 'development' ? `http://${process.env.USER}.devbox.com/public-site-assets/` : '/public-site-assets/',
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
next dev
running locally, served via nginx reverse proxyDescribe the Bug
HMR stopped working after I added a relative path assetPrefix.
In my org, we have unlimited of developer servers that could have any subdomain:
sally.devbox.com
,varoon.devbox.com
,bob.devbox.com
. I want to use assetPrefix to namespace the assets to a particular package of next.js.So, I add
assetPrefix:
/public-site-assets/to
next.config.js`.The rendered templates behave as expected way: On sally's box they point to
sally.devbox.com/public-site-assets/..
On bob's box they point tobob.devbox.com/public-site-assets/..
On varoon's box they point tovaroon.devbox.com/public-site-assets/..
However, hot module reloading has stopped working. In the console I see the following warning:
nginx WebSocket is closed before the connection is established.
It isn't an error. It appears to be timing out.My nginx servers pass along the proper http upgrade headers to support wss. It was working before adding the prefix.
After doing some digging, I found the PR that first fixed HMR for assetPrefixes: https://github.com/vercel/next.js/pull/30632.
However, I notice something odd when reading through the code. The hmr logic is expected the paths to either include a protocol or be absolute. i.e., It is always prepending a slash if there is no protocol. My guess is that the request is being sent off into the ether, causing the timeout.
I proved my hypothesis by hardcoding the assetPrefix to the server address that I am using:
sally.devbox.com/public-site-assets/
. Bingo, Bango; it works again.It looks like this code is still in the main branch: https://github.com/vercel/next.js/pull/30632/files#diff-503b31fa14e16da2eff70176a73da5d351caaa0f714f1ad67e61590024568801R494-R496
Expected Behavior
HMR should support both absolute and relative paths.
Link to reproduction
https://codesandbox.io/s/boring-dawn-1jcue5
To Reproduce
add a relative path to assetPrefix in
next.config.js