Skip to content

react-helmet warns under StrictMode #350

Open

Description

@brian-smith-tcril

react-helmet warns under StrictMode. Every page that sets its title the way ADR 0015 prescribes prints React's UNSAFE_componentWillMount warning in the browser console, once per page load.

Found while porting Learning's progress tab (openedx/frontend-app-learning#2190).

Note

The details below were generated by Claude (Claude Code) and reviewed before posting.

Claude Plan

How it happens today

  • An app sets its document title with <Helmet> from react-helmet: ADR 0015 (status Proposed) says "Every route-level page component in an app is responsible for setting the document title. Apps do this with <Helmet> from react-helmet", each app declaring the dependency, and the migration guide's Set the document title on every route-level page gives the code.

  • react-helmet 6.1.0 builds Helmet on react-side-effect: withSideEffect(…)(NullComponent). react-side-effect 2.1.2 wraps it in a class component named SideEffect(NullComponent) that defines UNSAFE_componentWillMount.

  • The shell renders the site inside <StrictMode>.

  • Observed on a development site running Learning's frontend-base package (@openedx/frontend-base 2.0.0-alpha.17, React 18.3.1, react-helmet 6.1.0), in the browser console on loading a page:

    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.
    
    * Move code with side effects to componentDidMount, and set initial state in the constructor.
    
    Please update the following components: SideEffect(NullComponent)
    
  • react-helmet's latest release on npm is 6.1.0, published 2020-06-08.

What the docs say

  • React's <StrictMode> reference, Fixing deprecation warnings enabled by Strict Mode: "React warns if some component anywhere inside a <StrictMode> tree uses one of these deprecated APIs: UNSAFE_ class lifecycle methods like UNSAFE_componentWillMount."
  • ADR 0015, Rejected alternatives, Standardizing on react-helmet-async: "react-helmet-async is generally recommended over react-helmet for React 18+ projects: it avoids act() warnings, supports streaming SSR, and is actively maintained." and "Standardizing on react-helmet-async across all apps is a worthwhile follow-up but does not need to block this decision". The ADR does not mention this warning.
  • The React 19 release post, Support for Document Metadata: "In the past, these elements would need to be inserted manually in an effect, or by libraries like react-helmet" and "In React 19, we're adding support for rendering document metadata tags in components natively".
  • The react-helmet-async README (3.1.0 on npm, peer react 16.6 to 19): "This package is a fork of React Helmet.", and under React 19, "Starting with version 3.0.0, this package detects the React version at runtime" and "you may not need this package at all — React 19's built-in metadata handling may be sufficient."

How it got here

Where it bites

Questions

  • Does react-helmet-async print this warning under React 18.3 in StrictMode? Not tested here.
  • When frontend-base moves to React 19, does React's own <title> hoisting do what ADR 0015 asks of Helmet, including one page's title replacing another's across a client-side navigation? Not tested here.
  • ADR 0015 is still Proposed. Is the library it names part of what is being decided?
  • Until the library changes, where does an app author following the migration guide learn that the pattern prints this warning?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions