Closed Leksat closed 6 months ago
@Leksat fantastic PR! Let me merge this and push 5.0.4 to NPM
5..0.4 is in NPM repository! Thank you for your contribution!
@Leksat we are investigating an issue we are seeing in our app not using WebSocket where the log lines are duplicated after this PR. If we revert to 5.0.3 its back to working.
Strict mode does a Mount, UnMount, Mount. When running in Non Strict mode (aka Production Mode) we only get the correct log lines.
@Leksat i left your change in place for websockets but for plain text mode I put it back the way it was.
See: https://github.com/melloware/react-logviewer/commit/03d35c0464cf8dfb08a7071c81134170aa00a253
It was noticed that
LazyLog
does not work properly with websockets on recent React versions.My websocket is sending multiple messages immediately after the connection is opened. Yet I observed only the first and the last message rendered in the component.
I tracked it down to
handleUpdate
:this.state
this.setState
However, as mentioned in the pitfall section of the
setState
documentation,this.setState
does not update the state immediately. So most of thehandleUpdate
calls were getting an outdated state.The PR fixes this by moving most of the
handleUpdate
code into athis.setState
callback.