{"_id":"react-helmet-async@3.1.0","bugs":{"url":"https://github.com/staylor/react-helmet-async/issues"},"dist":{"shasum":"25225288faf60c1d13e7522b05e9e1af1cf6a8ff","tarball":"http://registry-npm.ywwl.com/react-helmet-async/download/react-helmet-async-3.1.0.tgz","fileCount":16,"integrity":"sha512-IRwyrrgRCrtEEZoFb54Q/otpzGpWnOFV8bdY1C5VWovgtyOXq1jC/KCFs4xOxDaoKdTHPLta3qP2tI8QjDunQA==","signatures":[{"sig":"MEUCIC3uADu94rOYSg4o9lTzk8zIgrl8nZdWQc2F7AqH4drDAiEA0HsHSuRnjO3aOV31IiA1JSeKtoUyWqi7kX54KLBO36c=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEMCHzY9yP2kpH40+pHYuhZc7DHBrFiBjbGGguvRNCJnsG4CIDmO8rFsDoOaYe+tlMxo71L3E3SpfSW6cCEcQeRba/tG"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/react-helmet-async@3.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":116807,"size":30687,"noattachment":false,"key":"/react-helmet-async/-/react-helmet-async-3.1.0.tgz"},"main":"./lib/index.js","name":"react-helmet-async","pnpm":{"ignoredBuiltDependencies":["esbuild"]},"types":"./lib/index.d.ts","author":{"name":"Scott Taylor","email":"scott.c.taylor@mac.com"},"module":"./lib/index.esm.js","exports":{".":{"import":{"types":"./lib/index.d.ts","default":"./lib/index.esm.js"},"require":{"types":"./lib/index.d.ts","default":"./lib/index.js"}},"./package.json":"./package.json"},"gitHead":"182e2fc19d4a8b0b5312c4bdb401c113628f239b","license":"Apache-2.0","scripts":{"lint":"oxlint --deny-warnings && oxfmt --check","test":"vitest run","clean":"rimraf lib","types":"tsc --project tsconfig.build.json","compile":"pnpm run clean && tsx build.ts && pnpm run types","prepare":"pnpm run compile && husky","release":"tsx scripts/release.ts","lint-fix":"oxlint --fix && oxfmt","test:all":"pnpm test && pnpm run test:e2e","test:e2e":"pnpm run test:e2e:server && pnpm run test:e2e:browser","test-watch":"vitest watch","test-update":"vitest run -u","release-notes":"tsx scripts/release-notes.ts","test:e2e:server":"vitest run --config e2e/vitest.config.mts","test:e2e:browser":"playwright test --config e2e/playwright.config.ts"},"version":"3.1.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"a29b3ee1-e1c0-4c4c-b8ea-7ac05fe9c020"}},"homepage":"https://github.com/staylor/react-helmet-async#readme","keywords":["react","helmet","head","meta","title","seo","ssr","react-19"],"repository":{"url":"git+https://github.com/staylor/react-helmet-async.git","type":"git"},"_npmVersion":"11.19.1","description":"Thread-safe Helmet for React 16–18, with native support for React 19+","directories":{},"maintainers":[{"name":"wonderboymusic","email":"scott.c.taylor@mac.com"}],"sideEffects":false,"_nodeVersion":"24.22.2","dependencies":{"react-fast-compare":"^3.2.2"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.34.5","devDependencies":{"tsx":"4.23.15","vite":"8.3.7","acorn":"8.19.0","husky":"9.1.7","jsdom":"31.0.0","oxfmt":"0.77.0","react":"18.3.1","oxlint":"1.93.0","rimraf":"6.1.4","vitest":"5.1.0","esbuild":"0.28.2","react-19":"npm:react@19.3.0","react-dom":"18.3.1","typescript":"7.0.2","@types/node":"24.19.2","@types/react":"18.3.31","react-dom-19":"npm:react-dom@19.3.0","@commitlint/cli":"21.2.4","@playwright/test":"1.65.0","@types/react-dom":"18.3.7","@testing-library/dom":"10.4.2","@vitejs/plugin-react":"6.3.0","@testing-library/jest-dom":"7.0.1","@wonderboymusic/oxc-config":"2.0.0","@commitlint/config-conventional":"21.2.4"},"peerDependencies":{"react":"^16.6.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-helmet-async_3.1.0_1794431282271_0.8785180436037465"},"readme":"# react-helmet-async\n\n[![CI](https://github.com/staylor/react-helmet-async/actions/workflows/ci.yml/badge.svg)](https://github.com/staylor/react-helmet-async/actions/workflows/ci.yml)\n\n[Announcement post on Times Open blog](https://open.nytimes.com/the-future-of-meta-tag-management-for-modern-react-development-ec26a7dc9183)\n\nThis package is a fork of [React Helmet](https://github.com/nfl/react-helmet).\n`<Helmet>` usage is synonymous, but server and client now requires `<HelmetProvider>` to encapsulate state per request.\n\n`react-helmet` relies on `react-side-effect`, which is not thread-safe. If you are doing anything asynchronous on the server, you need Helmet to encapsulate data on a per-request basis, this package does just that.\n\nRelease notes, including breaking changes, are in [CHANGELOG.md](./CHANGELOG.md).\n\n## Installation\n\n```bash\nnpm install react-helmet-async\n```\n\n`react` 16.6 through 19 is a peer dependency.\n\n## React 19\n\nReact 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:\n\n- **React 19+**: `<Helmet>` renders actual DOM elements and lets React handle hoisting them to `<head>`. Mounted `<Helmet>` instances are merged as on React 16–18: the innermost title wins and uses the nearest `titleTemplate`, and duplicate tags render once, from the innermost instance, with the exceptions noted below. `<HelmetProvider>` becomes a transparent passthrough. In the browser the API works as before, except that `onChangeClientState` is never called and `defer` has no effect. Server rendering needs changes: `<HelmetProvider>` doesn't fill in `context`, so render the whole document with React instead of reading `helmetContext.helmet` (see [Streams](#streams)); `htmlAttributes` and `bodyAttributes` are only applied in the browser; and `prioritizeSeoTags` and the `helmetData` prop have no effect.\n- **React 16–18**: The existing behavior is preserved. `<Helmet>` collects all instances, deduplicates tags, and applies changes to the DOM via manual manipulation (client) or serializes them for the response (server).\n\n> **Note:** `htmlAttributes` and `bodyAttributes` do not have a React 19 equivalent, so they are still applied via direct DOM manipulation on both code paths.\n\n> **Note:** On the server, each `<Helmet>` still renders its own tags, because React renders the HTML in a single pass; they are merged after hydration. When hydrating, React reuses only the first `<title>` in the document, so a second server-rendered `<title>` stays in `<head>` after the merged one.\n\n> **Note:** React 19 loads an async `<script src>`, and a `<link rel=\"stylesheet\">` or `<style>` with `precedence`, only once per URL and keeps the attributes it rendered first. When two `<Helmet>`s render one of these for the same URL, the outer one's attributes stay, and a `<Helmet>` that mounts later can't change them.\n\n> **Note:** With `createRoot`, React leaves a `<title>` it did not render, such as a placeholder in `index.html`, where it is. Helmet's `<title>` goes before it, so browsers show Helmet's title and fall back to the placeholder when no `<Helmet>` sets one. Remove the placeholder if you don't want two `<title>` elements.\n\nIf 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.\n\n## Usage\n\n**New in 1.0.0:** No more default export! `import { Helmet } from 'react-helmet-async'`\n\nThe main way that this package differs from `react-helmet` is that it requires using a Provider to encapsulate Helmet state for your React tree. If you use libraries like Redux or Apollo, you are already familiar with this paradigm:\n\n```javascript\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { Helmet, HelmetProvider } from 'react-helmet-async';\n\nconst app = (\n  <HelmetProvider>\n    <App>\n      <Helmet>\n        <title>Hello World</title>\n        <link rel=\"canonical\" href=\"https://www.tacobell.com/\" />\n      </Helmet>\n      <h1>Hello World</h1>\n    </App>\n  </HelmetProvider>\n);\n\ncreateRoot(document.getElementById('app')).render(app);\n```\n\nOn the server, we will no longer use static methods to extract state. `react-side-effect`\nexposed a `.rewind()` method, which Helmet used when calling `Helmet.renderStatic()`. Instead, we are going\nto pass a `context` prop to `HelmetProvider`, which will hold our state specific to each request.\n\n```javascript\nimport React from 'react';\nimport { renderToString } from 'react-dom/server';\nimport { Helmet, HelmetProvider } from 'react-helmet-async';\n\nconst helmetContext = {};\n\nconst app = (\n  <HelmetProvider context={helmetContext}>\n    <App>\n      <Helmet>\n        <title>Hello World</title>\n        <link rel=\"canonical\" href=\"https://www.tacobell.com/\" />\n      </Helmet>\n      <h1>Hello World</h1>\n    </App>\n  </HelmetProvider>\n);\n\nconst html = renderToString(app);\n\nconst { helmet } = helmetContext;\n\n// helmet.title.toString() etc…\n```\n\n> **React 19 SSR note:** When using React 19, `<title>`, `<meta>`, and `<link>` tags rendered inside `<Helmet>` are included directly in the React render output and hoisted to `<head>` by React itself. The `context` object will not be populated with helmet state on React 19. If you rely on the `context` for server rendering, render the whole document, `<html>` and `<head>` included, with React instead of a string template; see the React 19 note under [Streams](#streams).\n\n## Streams\n\nOn React 18, `<Helmet>` adds nothing to React's HTML output; it collects tags into `helmetContext`. To stream with [`renderToPipeableStream`](https://react.dev/reference/react-dom/server/renderToPipeableStream), write the `<head>` yourself in `onShellReady`, then call `pipe()`. At that point React hasn't written anything yet, and `helmetContext.helmet` holds the tags from every `<Helmet>` in the shell:\n\n```javascript\nimport { createServer } from 'node:http';\nimport { PassThrough } from 'node:stream';\n\nimport React from 'react';\nimport { renderToPipeableStream } from 'react-dom/server';\nimport { Helmet, HelmetProvider } from 'react-helmet-async';\n\nconst App = () => (\n  <>\n    <Helmet>\n      <title>Hello World</title>\n      <link rel=\"canonical\" href=\"https://www.tacobell.com/\" />\n    </Helmet>\n    <h1>Hello World</h1>\n  </>\n);\n\n// Returns the HTML that goes before and after the app\nconst template = (helmet) => [\n  `<!DOCTYPE html>\n<html ${helmet.htmlAttributes.toString()}>\n  <head>\n    ${helmet.title.toString()}\n    ${helmet.meta.toString()}\n    ${helmet.link.toString()}\n  </head>\n  <body ${helmet.bodyAttributes.toString()}>\n    <div id=\"root\">`,\n  `</div>\n  </body>\n</html>`,\n];\n\ncreateServer((req, res) => {\n  const helmetContext = {};\n\n  const { pipe } = renderToPipeableStream(\n    <HelmetProvider context={helmetContext}>\n      <App />\n    </HelmetProvider>,\n    {\n      onShellReady() {\n        const [header, footer] = template(helmetContext.helmet);\n        res.setHeader('Content-Type', 'text/html; charset=utf-8');\n        res.write(header);\n        // pipe() ends its destination, so give it a PassThrough and end res yourself\n        const body = new PassThrough();\n        body.pipe(res, { end: false });\n        body.on('end', () => res.end(footer));\n        pipe(body);\n      },\n      onShellError() {\n        res.statusCode = 500;\n        res.setHeader('Content-Type', 'text/html; charset=utf-8');\n        res.end('<h1>Something went wrong</h1>');\n      },\n    }\n  );\n}).listen(3000);\n```\n\nWrite `base`, `style`, `script`, `noscript`, and `priority` (see [Prioritizing tags for SEO](#prioritizing-tags-for-seo)) into the template the same way if your `<Helmet>`s use them.\n\nTo hydrate the page, add your client bundle with the `bootstrapScripts` option, for example `bootstrapScripts: ['/client.js']` (the handler above renders the app for every URL, so serve that file separately), and call `hydrateRoot(document.getElementById('root'), <HelmetProvider><App /></HelmetProvider>)` in it.\n\n`onShellReady` doesn't wait for `<Suspense>` boundaries that are still loading. A `<Helmet>` inside one renders after the head has gone out, so its tags are missing from the HTML. `<Helmet>` applies them in the browser once that boundary hydrates, but crawlers that don't run JavaScript never see them. If crawlers need those tags, keep that `<Helmet>` outside the boundary, or write the head in `onAllReady` instead, which fires once every boundary has resolved. The response then doesn't start until the whole page is ready, so you may want to do that only for crawlers. With the body of `onShellReady` moved into a `send()` function:\n\n```javascript\nconst isCrawler = /bot|crawler|spider/i.test(req.headers['user-agent'] ?? '');\n\nconst { pipe } = renderToPipeableStream(app, {\n  onShellReady() {\n    if (!isCrawler) send();\n  },\n  onAllReady() {\n    // Also fires after a shell error, once onShellError has responded\n    if (isCrawler && !res.headersSent) send();\n  },\n  onShellError() {\n    // Same as above\n  },\n});\n```\n\n`renderToNodeStream`, which this section used to show, is deprecated in React 18 and removed in React 19. React 18's version waits for every Suspense boundary before it writes anything, so to keep that behavior when you switch, write the head in `onAllReady` instead of `onShellReady`.\n\n> **React 19:** `<HelmetProvider>` doesn't fill in `context` on React 19, so `helmetContext.helmet` stays `undefined` and the template above doesn't apply. React 19 hoists the `<title>`, `<meta>`, and `<link>` tags that `<Helmet>` renders into `<head>` itself, including when streaming with `renderToPipeableStream` or `renderToReadableStream`, so render the whole document, `<html>` included, and pipe it straight to the response. Tags inside a boundary that's still loading arrive later with that boundary's content, after `</head>`, so pipe in `onAllReady` if crawlers need them in `<head>`.\n\n## Usage in Jest\n\nWhile testing in using jest, if there is a need to emulate SSR, the following string is required to have the test behave the way they are expected to.\n\n```javascript\nimport { HelmetProvider } from 'react-helmet-async';\n\nHelmetProvider.canUseDOM = false;\n```\n\n> This is only relevant for React 16–18. On React 19, `HelmetProvider` is a passthrough and `canUseDOM` has no effect.\n\n## Deferred updates\n\nOn the client, `<Helmet>` applies its changes in the next animation frame, so when several `<Helmet>` instances change in one render, the document is updated once with the latest state. Browsers pause animation frames in background tabs, so if no frame comes within 100 ms the changes are applied anyway. A title set while the tab is in the background, such as an unread count, shows up after about a second, since browsers also throttle timers in background tabs.\n\nSet `defer={false}` to apply changes synchronously instead. As with other props, the value on the innermost `<Helmet>` applies:\n\n```javascript\n<Helmet defer={false}>\n  <title>Hello World</title>\n</Helmet>\n```\n\n> **React 19:** `defer` has no effect on React 19. React renders the tags itself, and `htmlAttributes` and `bodyAttributes` are applied as soon as `<Helmet>` mounts or updates.\n\n## Prioritizing tags for SEO\n\nIt is understood that in some cases for SEO, certain tags should appear earlier in the HEAD. Using the `prioritizeSeoTags` flag on any `<Helmet>` component allows the server render of react-helmet-async to expose a method for prioritizing relevant SEO tags.\n\nIn the component:\n\n```javascript\n<Helmet prioritizeSeoTags>\n  <title>A fancy webpage</title>\n  <link rel=\"notImportant\" href=\"https://www.chipotle.com\" />\n  <meta name=\"whatever\" value=\"notImportant\" />\n  <link rel=\"canonical\" href=\"https://www.tacobell.com\" />\n  <meta property=\"og:title\" content=\"A very important title\" />\n  <meta charSet=\"utf-8\" />\n</Helmet>\n```\n\nIn your server template:\n\n<!-- oxfmt-ignore -->\n```javascript\n<html>\n  <head>\n    ${helmet.title.toString()}\n    ${helmet.priority.toString()}\n    ${helmet.meta.toString()}\n    ${helmet.link.toString()}\n    ${helmet.script.toString()}\n  </head>\n  ...\n</html>\n```\n\nWill result in:\n\n```html\n<html>\n  <head>\n    <title>A fancy webpage</title>\n    <meta charset=\"utf-8\" />\n    <meta property=\"og:title\" content=\"A very important title\" />\n    <link rel=\"canonical\" href=\"https://www.tacobell.com\" />\n    <meta name=\"whatever\" value=\"notImportant\" />\n    <link rel=\"notImportant\" href=\"https://www.chipotle.com\" />\n  </head>\n  ...\n</html>\n```\n\n`<meta charset>` is always the first prioritized tag, because browsers only honor it within the first 1024 bytes of the document.\n\nA list of prioritized tags and attributes can be found in [constants.ts](./src/constants.ts).\n\n> **React 19:** The `prioritizeSeoTags` flag has no effect on React 19, since tags are rendered as regular JSX elements and their order in `<head>` is determined by React's rendering order.\n\n## Usage without Context\n\nYou can optionally use `<Helmet>` outside a context by manually creating a stateful `HelmetData` instance, and passing that stateful object to each `<Helmet>` instance:\n\n```js\nimport React from 'react';\nimport { renderToString } from 'react-dom/server';\nimport { Helmet, HelmetData } from 'react-helmet-async';\n\nconst helmetData = new HelmetData({});\n\nconst app = (\n  <App>\n    <Helmet helmetData={helmetData}>\n      <title>Hello World</title>\n      <link rel=\"canonical\" href=\"https://www.tacobell.com/\" />\n    </Helmet>\n    <h1>Hello World</h1>\n  </App>\n);\n\nconst html = renderToString(app);\n\nconst { helmet } = helmetData.context;\n```\n\n> **React 19:** The `helmetData` prop is ignored on React 19, since `<Helmet>` renders elements directly without the need for external state management.\n\n## Compatibility\n\n| React Version | Behavior                                                         |\n| ------------- | ---------------------------------------------------------------- |\n| 16.6+         | Full support via `HelmetProvider` context and manual DOM updates |\n| 17.x          | Full support via `HelmetProvider` context and manual DOM updates |\n| 18.x          | Full support via `HelmetProvider` context and manual DOM updates |\n| 19.x+         | Renders native JSX elements; React handles `<head>` hoisting     |\n\n## Development\n\nUse the Node.js version in `.nvmrc` (CI also runs 22 and 26) and the pnpm version in `packageManager`. Linting and formatting use [oxlint](https://oxc.rs/docs/guide/usage/linter) and [oxfmt](https://oxc.rs/docs/guide/usage/formatter) with [`@wonderboymusic/oxc-config`](https://github.com/staylor/oxc-config).\n\n```bash\npnpm install\npnpm lint            # oxlint + oxfmt --check\npnpm lint-fix        # apply lint fixes and formatting\npnpm test            # unit tests\npnpm run test:e2e    # server + browser e2e tests\npnpm run test:all    # everything\n```\n\nCI runs the type check, lint and all tests on every push, and on pull requests from forks.\n\n### Releasing\n\nAdd each user-facing change to the `## [Unreleased]` section of [CHANGELOG.md](./CHANGELOG.md) in the pull request that makes it. To release, run this on an up-to-date `main`:\n\n```bash\npnpm release minor   # or major, patch, or an exact version such as 3.1.0\n```\n\nIt moves the unreleased entries into a section for the new version, bumps `package.json`, and opens a `release/v<version>` pull request. Merging that pull request runs the [Publish workflow](./.github/workflows/publish.yml), which publishes the package to npm with provenance and creates the `v<version>` GitHub release and tag, with the changelog section as the release notes. `pnpm release minor --dry-run` prints the next version and its notes without changing anything.\n\nThe workflow authenticates to npm through [trusted publishing](https://docs.npmjs.com/trusted-publishers), so there is no npm token to manage. On npmjs.com, the package's trusted publisher has to be GitHub Actions with user `staylor`, repository `react-helmet-async` and workflow `publish.yml`, with `npm publish` allowed.\n\n## License\n\nLicensed under the Apache 2.0 License, Copyright © 2018 Scott Taylor\n","publish_time":1794431282434,"_cnpm_publish_time":1794431282434,"dist-tags":{"alpha":"2.0.5-alpha","beta":"2.0.5-beta","latest":"3.1.0","next":"2.0.5-next"}}