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

Head and meta tags handling #1537

Merged
merged 29 commits into from Aug 16, 2019
Merged

Head and meta tags handling #1537

merged 29 commits into from Aug 16, 2019

Conversation

revanth0212
Copy link
Contributor

Added wrappers around the HeadProvider and Title components of react-head. Also exporting Meta, Link and Style tags directly from react-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

@vercel
Copy link

vercel bot commented Aug 7, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://pwa-studio-git-headandmetatagshadling.mmansoor.now.sh

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Aug 7, 2019

Fails
🚫 Missing "Description" section. Please add it back, with detail.
🚫 Missing "Verification Steps" section. Please add it back, with detail.
🚫

No linked issue found. Please link a relevant open issue by adding the text "closes #<issue_number>" in your PR.

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

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.

Generated by 🚫 dangerJS against 75d9637

Copy link
Contributor

@supernova-at supernova-at left a 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', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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/headProvider.js Outdated Show resolved Hide resolved
packages/venia-concept/src/components/Head/headProvider.js Outdated Show resolved Hide resolved
packages/venia-concept/src/components/Head/headProvider.js Outdated Show resolved Hide resolved
@@ -0,0 +1,19 @@
import React, { useEffect } from 'react';
import { HeadProvider as _HeadProvider } from 'react-head';
Copy link
Contributor

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 😬

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

packages/venia-concept/src/components/Head/title.js Outdated Show resolved Hide resolved
packages/venia-concept/src/components/Head/title.js Outdated Show resolved Hide resolved
@supernova-at
Copy link
Contributor

#1537 (comment). Please fill out the PR template :)

Looks like there are some conflicts to resolve as well 👍

@supernova-at
Copy link
Contributor

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?

@revanth0212
Copy link
Contributor Author

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, react-head does not support the manipulations of tags (like removing). I have checked their codebase, it is possible for us to go ahead and add manipulations API as submit a PR, or the simplest would be to write a simple wrapper around Meta (just like how we did for Title) that does these kinds of manipulations.

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?

@zetlen zetlen changed the title Head and meta tags hadling Head and meta tags handling Aug 16, 2019
@m2-community-project m2-community-project bot moved this from Review in Progress to Reviewer Approved in Pull Request Progress Aug 16, 2019
@dpatil-magento dpatil-magento moved this from Reviewer Approved to QA In Progress in Pull Request Progress Aug 16, 2019
@dpatil-magento
Copy link
Contributor

dpatil-magento commented Aug 16, 2019

@revanth0212 Please check unit test failures. Able to reproduce on my local as well.
packages/venia-ui/lib/components/App/tests/app.spec.js
packages/venia-ui/lib/RootComponents/Category/tests/categoryContent.spec.js

Also If I visit any page for the first time then title shows null - Venia for fraction of time.

@vercel vercel bot temporarily deployed to staging August 16, 2019 20:03 Inactive
Copy link
Contributor

@jimbo jimbo left a 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.

@jimbo
Copy link
Contributor

jimbo commented Aug 16, 2019

This is ready to go pending QA approval.

@dpatil-magento dpatil-magento merged commit 0186e9a into develop Aug 16, 2019
@dpatil-magento dpatil-magento deleted the headAndMetaTagsHadling branch August 16, 2019 21:40
@m2-community-project m2-community-project bot moved this from QA In Progress to Done in Pull Request Progress Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine pkg:venia-ui version: Minor This changeset includes functionality added in a backwards compatible manner.
Development

Successfully merging this pull request may close these issues.

[Bug] Handle title and meta tags for navigation on client side
6 participants