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
Head and meta tags handling #1537
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://pwa-studio-git-headandmetatagshadling.mmansoor.now.sh |
If your PR is missing information, check against the original template here. At a minimum you must have the section headers from the template and provide some information in each section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes requested. I'd love to be able to remove the custom <title>
filtering if we can. That'll let us use the components directly from react-head
, which means less code for us to maintain 😉
|
||
afterEach(cleanup); | ||
|
||
test('snapshot testing HeadProvider', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the tests have nice descriptive names for what they are testing, for example "HeadProvider should replace all previous title tags with the latest tag".
Can you provide a nice descriptive name for this test as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what to call this. It is a casual snapshot test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"HeadProvider by itself doesn't render anything" ?
Basically you just want someone who is only looking at the snapshot to be able to ensure it is correct.
packages/venia-concept/src/components/Head/__tests__/headProvider.spec.js
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,19 @@ | |||
import React, { useEffect } from 'react'; | |||
import { HeadProvider as _HeadProvider } from 'react-head'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of the underscore as the first character of a React component 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What shall I change it to? I wanted to signify vanila HeadProvider
as _HeadProvider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I wasn't really sure either 😝
What if we called our function VeniaHeadProvider
, and it rendered react-head
's HeadProvider
.
Because VeniaHeadProvider
would be the default export, you could still import it from other files as HeadProvider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Let me get this done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@supernova-at The pattern of naming things VeniaHeadProvider
after the package is kind of frustrating in practice. These components get used in implementations that aren't identified as Venia anymore and that naming doesn't feel good to see, so we rewrite and maintain that rewrite. It makes upstream integration more complex.
#1537 (comment). Please fill out the PR template :) Looks like there are some conflicts to resolve as well 👍 |
I also have a small concern about stale meta tags hanging around. If Page2 provides the same meta tag as Page1 with a different value, it'll get overwritten properly. But what if Page1 has a specific meta tag that Page2 doesn't care / know about? Won't that just stick around forever? |
If the new page is a new HTML it shouldn't unless the new markup has that meta tag. If it a page transition using react-router, then it is on us to clear those tags. As of today, The ticket dint mention those use cases but you are right, they will be hanging around and there has to be a way to delete the existing ones. Shall I go ahead and write that wrapper? What do you say @jimbo @supernova-at? |
@revanth0212 Please check unit test failures. Able to reproduce on my local as well. Also If I visit any page for the first time then title shows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well. We can iterate on the specific title format in the future.
This is ready to go pending QA approval. |
Added wrappers around the
HeadProvider
andTitle
components ofreact-head
. Also exportingMeta
,Link
andStyle
tags directly fromreact-head
.These 5 components will be used to handle the document's
head
tag.To be able to use the components anywhere in the app, the app has to be wrapped inside
HeadProvider
which provides the context needed to maintain all the rendered tags.Closes 422