staylor / react-helmet-async

Thread-safe Helmet for React 16+ and friends
Apache License 2.0
2.1k stars 154 forks source link

using UNSAFE_componentWillMount in strict mode #213

Open ali-eljerrari opened 8 months ago

ali-eljerrari commented 8 months ago

Warning: Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://reactjs.org/link/unsafe-component-lifecycles for details.

Please update the following components: SideEffect(NullComponent2)

any fix for this warning???

gilluminate commented 8 months ago

After some extensive debugging of the code, I've determined that componentWillMount in the Dispatcher.tsx file is firing after the init when using this package in a NextJS project. This causes the helmetInstances object to be removed and never gets applied. This is the only reason no one is able to use this package for client side <head> updates in NextJS's new App routing! I'm guessing this affects other similar frameworks as well.

As per the 6 year old note in the code

  // componentWillMount will be deprecated
  // for SSR, initialize on first render
  // constructor is also unsafe in StrictMode

Can that simply be removed entirely?

(side note: componentDidUpdate never even fires)