Skip to content

feat: add usePageTitle hook - #353

Open
arbrandes wants to merge 1 commit into
openedx:mainfrom
arbrandes:arbrandes/use-page-title
Open

arbrandes wants to merge 1 commit into
openedx:mainfrom
arbrandes:arbrandes/use-page-title

Conversation

@arbrandes

Copy link
Copy Markdown
Contributor

Description

Adds a usePageTitle() hook that apps call from each route-level page to set the document title, instead of using <Helmet> from react-helmet, which warns under StrictMode. Closes #350.

When a route and one of its child routes both set a title, the innermost one wins. The shell's own not-found and error pages now set titles as well.

ADR 0015 and the migration guide are updated to prescribe the hook, with react-helmet and react-helmet-async moved to rejected alternatives.

LLM usage notice

Built with assistance from Claude.

Apps set the document title through frontend-base instead of
react-helmet, which warns under StrictMode.  ADR 0015 and the
migration guide now prescribe the hook.

Co-Authored-By: Claude <noreply@anthropic.com>
Comment on lines +86 to +103
Rejected alternatives
=====================

``<Helmet>`` from ``react-helmet``
----------------------------------

This is what apps already used, and what an earlier draft of this ADR
prescribed. It was rejected because the library's last release dates from
2020, and it relies on ``UNSAFE_componentWillMount``, so every page that uses
it logs a React warning under the shell's ``<StrictMode>``.

``<Helmet>`` from ``react-helmet-async``
----------------------------------------

``react-helmet-async`` is maintained and does not warn, but every
``<Helmet>`` needs a ``<HelmetProvider>`` above it, which the shell would
have to render. frontend-base would own the title anyway, with an extra
dependency, for a library apps would only use to set ``<title>``.

@bradenmacdonald bradenmacdonald Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helmet is unmaintained because <title> support is built into React 19, along with other <head> elements. You simply put <title>blah</title> anywhere in your component tree, and it works. Since that's the new standard, I think it should be at least listed here as a rejected option. But I would prefer that we aim to use it instead of a custom hook.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding to this, from the react-helmet-async README:

React 19 has built-in support for hoisting <title>, <meta>, <link>, <style>, and <script> elements to <head>. Starting with version 3.0.0, this package detects the React version at runtime:

  • React 19+: <Helmet> renders actual DOM elements and lets React handle hoisting them to <head>. [...]
  • React 16–18: The existing behavior is preserved. <Helmet> collects all instances, deduplicates tags, and applies changes to the DOM via manual manipulation [...]

[...]

If you are starting a new React 19 project and do not need htmlAttributes/bodyAttributes, titleTemplate/defaultTitle, or merging of nested <Helmet>s, you may not need this package at all — React 19's built-in metadata handling may be sufficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's all well and good, but we're not on React 19 yet. So the choice is to either live with the warning until then, or use a hook - which we can update to use the React 19 feature, if we want.

What doesn't make sense is to add a different dependency such as react-helmet-async.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm completely fine with either approach, as long as the React 19 <title> alternative is explicitly discussed in the ADR.

But personally I'd rather not add 50 lines of custom code and a couple hundred lines of test code just to implement a workaround to further support delaying the React 19 upgrade which has already been delayed by two releases. And once we start using this new hook in many different MFEs, it's less likely we'll refactor it to the simple upstream approach that doesn't require any custom code. So we're basically trading a tiny amount of bloat now for getting rid of a single warning.

For perspective: opening the authoring MFE currently will log about 19 warnings that come from frontend-platform and 24 warnings that come from either Paragon or MFE components using defaultProps. If you open the xblock editors, you get dozens more warnings. And these things like defaultProps are mostly the same things that are blocking the React 19 upgrade (as I understand) - that's why React 18 is warning about them, after all. So I feel like the work of fixing warnings is mostly the same work as preparing for React 19, and if we want to fix the warnings we should focus on that (react 19 upgrade). One less warning is not meaningful to me when I've been annoyed by dozens and dozens of noisy warnings for years, along with the slow progress of addressing these upstream in Paragon.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react-helmet warns under StrictMode

3 participants