The componentDidMount method no execute on production mode
The method does not run in build mode. In the dev method yes.
create a page
`class Index extends React.Component {
componentDidMount() {
alert('Hola');
}
render() {
return 'hello';
}
}`
execute dev mode and check the alert()
I was waiting for the alert()
Thanks!
With the versi贸n 7.0.2 works
@martinvarelaaaa I just tried your snippet in a new app at it worked. Can you share a minimal test case which I can clone and try out?
@timneutkens can you explain why this issue has been closed without any explanation ?
I have the exact same problem with the latest version (8.0.3) ...
@Donov4n there was a comment from @giuseppeg who looked into it and can't reproduce. Without a clear reproduction we can't really look into issues. There's 164 open issues at this point in time, so we close issues that have been looked into and are not reproducible/actionable.
@Donov4n, @martinvarelaaaa I had the same issue while using 8.0.3. I updated Next to 8.0.4 and the issue is fixed.
This issue persists. I need to do something that seems very simple: Make an XHR GET request from the client once the page has been loaded. I don't even need the response of this request.
I've tried two methods so far:
fetch
within componentDidMount
of the Next.js page component.fetch
within componentDidMount
of a child component and render the child component.Both work fine in dev, but not in my production environment using a so-called "self-hosted custom server" (Express JS).
Please re-open @timneutkens
We have tests for the exact reproduction provided in this issue and it's passing fine, so no need to re-open.
I am seeing similar behaviour to @iMerica. Did you manage to solve this one? My componentDidMount
code works perfectly in dev
mode but fails in production
using a custom express server.
I'm experiencing this as well.
Edit: I found how to fix it in my case.. @timneutkens
I'm using polyfills. My webpack in next.config.js looks just like the with-polyfills example.
Apparently the text-encoding module I was using did not play nice with npm and "require".
//Polyfill necessary for Joi on some browsers
if (typeof window["TextEncoder"] !== "function") {
const TextEncodingPolyfill = require("text-encoding");
....
}
I replaced it with another text encoder and that did the job.
//Polyfill necessary for Joi on some browsers
if (typeof window["TextEncoder"] !== "function") {
const TextEncodingShim = require("text-encoding-shim");
window["TextEncoder"] = TextEncodingShim.TextEncoder;
window["TextDecoder"] = TextEncodingShim.TextDecoder;
}
So it seems this was happening due to a broken polyfill in my case.
Most helpful comment
@Donov4n, @martinvarelaaaa I had the same issue while using 8.0.3. I updated Next to 8.0.4 and the issue is fixed.