Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not properly working with new React18 root-api #669

Open
dersimoezdag opened this issue Feb 9, 2022 · 5 comments
Open

Not properly working with new React18 root-api #669

dersimoezdag opened this issue Feb 9, 2022 · 5 comments

Comments

@dersimoezdag
Copy link

I want to report a bug

On the new root-api (reactwg/react-18#5) react-helmet does not always properly set the meta-tags.

Using react-dom@18.0.0-rc.0-f2a59df48-20211208
and react-helmet@6.1.0

I'm not sure if it's related to react-helmet or the current react alpha. But the issue is only noticeable on the new root-api, not when using the old render method on the current alpha.

@felixh10r
Copy link

i can confirm this is an issue with stable react 18 root api. is this project actively maintained? i'd be happy to open a PR if desired.

@wongchichong
Copy link

I had used the root api 18 with react-helmet@6.1.0

import { createRoot } from 'react-dom/client'

const root = createRoot(document.getElementById("root"))
root.render()

found that some of the tags previously added by helmet will be removed by others nested helmet.
but when revert back to old syntax with react 18

render(, document.getElementById("root"))

the problem disappeared.

I can't replicate this problem in simple project in codesandbox, because react router involved.

@PaulMest
Copy link

PaulMest commented Aug 8, 2022

Seems like this is a fork that has more traction and is more actively maintained: https://github.com/staylor/react-helmet-async

@eyerean
Copy link

eyerean commented Nov 25, 2022

Maybe something like that could be used instead, if you don't want to replace packages:

import * as React from 'react';
import {Helmet as ReactHelmet, HelmetProps as ReactHelmetProps} from 'react-helmet';

interface HelmetProps extends ReactHelmetProps, React.PropsWithChildren {}

const Helmet = (props: HelmetProps) => <ReactHelmet {...props} />;

@eugeniosegala
Copy link

eugeniosegala commented Jan 13, 2023

I "solved" this problem by adding a key to the Helmet wrapper.

Something like:

<Helmet key={id}>
...
</Helmet>

Not a real solution but only a temporary workaround.

You can also probably add the key only to the single tag that needs to be refreshed 🤞

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

No branches or pull requests

6 participants