Comments (9)
This is the React tree on my dev env:
from react-head.
For some reasons the React Context did not make it to the HeadTag component, making this line fail:
Line 30 in b294fa7
Now I am using the redux (provider) with the connect method (consumer) on server side without any issue.
from react-head.
Could you try to wrap all other providers with HeadProvider? There can be a conflict between old and new context apis.
from react-head.
I am also trying react-helmet-async and I also got some weird errors.
I am doing something a little unconventional on the server side and this might be the issue.
I have an universal
folder a client
folder and a server
folder.
On the server side I using babel alone to transpile the few js files in the server
folder but then I use webpack to build the universal
bundle (on the server side).
The entry point it a top level component called Routes.
my server.js
file just require the build component like that:
const Layout = require("../../build/Routes.js").default
And then I use this top level component like this:
const rootComponent = PROD ? (
<IntlProvider locale={locale} messages={messages[locale]}>
<Provider store={store}>
<HeadProvider headTags={headTags}>
<StaticRouter location={location} context={context}>
<Layout />
</StaticRouter>
</HeadProvider>
</Provider>
</IntlProvider>
) : null;
My transpiled server
will still use the node_modules
folder during runtime.
While my Routes
bundle will include it own node_modules js file within the bundle.
Can you tell me if you think this is an issue?
Because from what I understood the React.Context should be the same (it is kind of statefull).
from react-head.
Now this should work though, but it doesn't:
on server.js
const Layout = require("../../build/Routes.js").default
const headTags = [];
const rootComponent = PROD ? (
<IntlProvider locale={locale} messages={messages[locale]}>
<Provider store={store}>
<StaticRouter location={location} context={context}>
<HeadProvider value={{headTags: headTags}}>
{[
<Title>Search</Title>,
<Meta name="description" content="Some Search" />,
<Meta property="og:title" content="Search" />,
<Meta property="og:image" content="path/to/search.jpg" />,
<Layout />,
]}
</HeadProvider>
</StaticRouter>
</Provider>
</IntlProvider>
) : null;
const markup = ReactDOMServer.renderToString(rootComponent);
fail with: invariant failed again
(node:4316) UnhandledPromiseRejectionWarning: Error: Invariant failed
at index (/home/pc/Documents/funspace/babysearch/isomorphic-react-redux-saga-ssr/node_modules/tiny-invariant/dist/tiny-invariant.cjs.js:13:11)
from react-head.
@TrySound
I tried to wrap my HeadTags with a HeadProvider within the universal
components but I still ge the same error
from react-head.
This error looks like you have two instances of head context. Make sure you use one instance in server side. Try to put console.log
in react-head/dist/index.cjs.js and react-head/dist/index.esm.js and then run your app.
from react-head.
@casertap What solution did you end up with here?
from react-head.
@oyeanuj Add HeadProvider in the root of the tree like said in docs.
from react-head.
Related Issues (20)
- Link canonical cascade HOT 1
- Expose HeadTag? HOT 2
- Question: Does it work without ssr for SEO, on fb and twitter ? HOT 1
- Children prop type missing in HeadProvider HOT 7
- Is this library still maintained? HOT 1
- Suggestion: use renderToStaticMarkup instead of renderToString HOT 4
- Some tags not collected HOT 4
- Development server not working HOT 2
- does not support ie9? HOT 2
- Proposal: headTagsToElement(headTags) HOT 1
- Element.remove() not supported in IE HOT 3
- Document usage with SSR streaming HOT 3
- TypeScript support HOT 3
- react-head supports meta update on lazy load HOT 3
- itemProp support on <Meta /> HOT 1
- canonical link is repeated HOT 1
- Title component doesn't override default <title> tag provided via HTML template HOT 10
- Entities in computed attribute values? Suggested approach? HOT 5
- RFC: Managing tags without extra markup HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-head.