-
Notifications
You must be signed in to change notification settings - Fork 229
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
Lite Site: Remove data-react-helmet="true" attributes from all tags within the html <head>
tag
#12350
Draft
karinathomasbbc
wants to merge
14
commits into
latest
Choose a base branch
from
remove-data-react-helmet-from-lite-pages
base: latest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Lite Site: Remove data-react-helmet="true" attributes from all tags within the html <head>
tag
#12350
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bd3c1e3
Remove data-react-helmet="true" attribute from all tags with the html…
karinathomasbbc f73c87f
Remove data-react-helmet from tags when rendering lite pages
karinathomasbbc f9f56ad
Simplify code
karinathomasbbc c98c63f
Simplify code
karinathomasbbc a89fe7e
Cast components which have had data-react-helmet removed to a ReactEl…
karinathomasbbc a67bd0d
Add an integration test to ensure data-react-helmet tags removed
karinathomasbbc 86475a6
Adding an integration for the gahuza lite homepage
karinathomasbbc 3a8ad54
Remove data-react-helmet from NextJS pages
karinathomasbbc 03b46f1
Support fetching lite live pages on local dev environment
karinathomasbbc 8855a39
Add an integration test for a lite live page
karinathomasbbc 0c6765f
Remove data-react-helmet from snapshots
karinathomasbbc 167a7fd
Add additional test scenarios
karinathomasbbc d7a8308
Snapshot for lite homepage integration test
karinathomasbbc 9ab74d1
Merge branch 'latest' into remove-data-react-helmet-from-lite-pages
karinathomasbbc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ import { | |
import parseAvRoute from '../parseAvRoute'; | ||
|
||
const removeLeadingSlash = (path: string) => path?.replace(/^\/+/g, ''); | ||
const removeAmp = (path: string) => path.split('.')[0]; | ||
const removeSuffix = (path: string) => path.split('.')[0]; | ||
const getArticleId = (path: string) => path.match(/(c[a-zA-Z0-9]{10,}o)/)?.[1]; | ||
const getCpsId = (path: string) => removeLeadingSlash(path); | ||
const getTVAudioId = (path: string) => removeLeadingSlash(path); | ||
|
@@ -155,7 +155,7 @@ const getId = ({ pageType, service, variant, env }: GetIdProps) => { | |
getIdFunction = () => null; | ||
break; | ||
} | ||
return pipe(getUrlPath, removeAmp, getIdFunction); | ||
return pipe(getUrlPath, removeSuffix, getIdFunction); | ||
}; | ||
|
||
export interface UrlConstructParams { | ||
|
@@ -257,9 +257,12 @@ const constructPageFetchUrl = ({ | |
const variantPath = variant ? `/${variant}` : ''; | ||
const host = `http://${process.env.HOSTNAME || 'localhost'}`; | ||
const port = process.env.PORT ? `:${process.env.PORT}` : ''; | ||
// pathname is the ID of the Live page without /service/live/, and supports both Tipo & CPS IDs | ||
|
||
let liveId = id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add a comment here? |
||
if (!isTipoIdCheck(id)) liveId = removeSuffix(pathname); | ||
|
||
fetchUrl = Url( | ||
`${host}${port}/api/local/${service}/live/${pathname}${variantPath}`, | ||
`${host}${port}/api/local/${service}/live/${liveId}${variantPath}`, | ||
); | ||
break; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/integration/pages/homePage/gahuzaLiteSite/__snapshots__/lite.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Lite Site Home Page Lite Site Cta should match snapshot 1`] = ` | ||
<section | ||
aria-labelledby="LiteSiteCta" | ||
class="bbc-1x0h7k" | ||
data-e2e="lite-cta" | ||
role="region" | ||
> | ||
<strong | ||
class="bbc-ory9gk" | ||
hidden="" | ||
id="LiteSiteCta" | ||
> | ||
Ahagusaba uburyo (ama mega) buke | ||
</strong> | ||
<div | ||
class="bbc-zudp5j" | ||
> | ||
<p | ||
class="bbc-11k1lfi" | ||
> | ||
Uriko ubona ku rubuga aherekana amakuru mu nyandiko gusa, hakoresha uburyo buke. Ja ku rubuga nyamukuru ubone amakuru mu nyandiko iherekejwe n'amasanamu. | ||
</p> | ||
<p | ||
class="bbc-vit5au" | ||
data-e2e="to-main-site" | ||
> | ||
<a | ||
class="bbc-16f79jf" | ||
data-ignore-lite="true" | ||
href="http://localhost:7080/gahuza" | ||
> | ||
<span | ||
class="bbc-x7bqmd" | ||
> | ||
Njana ku rubuga nyamukuru canke aho gusoma gusa | ||
</span> | ||
<svg | ||
aria-hidden="true" | ||
class="bbc-2wok52" | ||
focusable="false" | ||
height="12" | ||
viewBox="0 0 32 32" | ||
width="12" | ||
> | ||
<path | ||
d="M21.6 14.3L5.5 31h6.4l14.6-15L11.9 1H5.5l16.1 16.7v-3.4z" | ||
/> | ||
</svg> | ||
</a> | ||
</p> | ||
<p | ||
class="bbc-vit5au" | ||
data-e2e="information-page" | ||
> | ||
<a | ||
class="bbc-gcewl8" | ||
href="https://www.bbc.com/gahuza/articles/cn7y7pvem0vo.lite" | ||
> | ||
<span | ||
class="bbc-1qfjcgd" | ||
> | ||
Ibindi vyerekeye ingene urwo rubuga rugutwara uburyo (ama mega) buke | ||
</span> | ||
</a> | ||
</p> | ||
</div> | ||
</section> | ||
`; |
12 changes: 12 additions & 0 deletions
12
src/integration/pages/homePage/gahuzaLiteSite/lite.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @service gahuza | ||
* @pathname /gahuza | ||
*/ | ||
|
||
import { runLiteSiteTests } from '../../../common'; | ||
|
||
describe('Lite Site', () => { | ||
describe(pageType, () => { | ||
runLiteSiteTests(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
...erver/Document/Renderers/litePageTransforms/removeDataReactHelmetAttribute/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import serialiseForScript from '#app/lib/utilities/serialiseForScript'; | ||
import removeDataReactHelmetAttribute from '.'; | ||
|
||
describe('removeDataReactHelmetAttribute', () => { | ||
it('removes data-react-helmet from meta tags', () => { | ||
const metaTags = [ | ||
<meta data-react-helmet="true" name="name1" content="content1" />, | ||
<meta data-react-helmet="true" name="name2" content="content2" />, | ||
]; | ||
|
||
expect(removeDataReactHelmetAttribute(metaTags)).toStrictEqual([ | ||
<meta name="name1" content="content1" />, | ||
<meta name="name2" content="content2" />, | ||
]); | ||
}); | ||
|
||
it('removes data-react-helmet from link tags', () => { | ||
const linkTags = [ | ||
<link | ||
data-react-helmet="true" | ||
rel="canonical" | ||
href="https://www.bbc.com/pidgin" | ||
/>, | ||
<link | ||
data-react-helmet="true" | ||
rel="icon" | ||
href="https://www.bbc.com/pidgin" | ||
/>, | ||
]; | ||
|
||
expect(removeDataReactHelmetAttribute(linkTags)).toStrictEqual([ | ||
<link rel="canonical" href="https://www.bbc.com/pidgin" />, | ||
<link rel="icon" href="https://www.bbc.com/pidgin" />, | ||
]); | ||
}); | ||
|
||
it('removes data-react-helmet from script tags', () => { | ||
const scriptTags = [ | ||
<script data-react-helmet="true" type="text/javascript"> | ||
console.log(`Hello World`); | ||
</script>, | ||
<script data-react-helmet="true" type="application/ld+json"> | ||
{serialiseForScript({ key: 'value' })} | ||
</script>, | ||
]; | ||
|
||
expect(removeDataReactHelmetAttribute(scriptTags)).toStrictEqual([ | ||
<script type="text/javascript">console.log(`Hello World`);</script>, | ||
<script type="application/ld+json"> | ||
{serialiseForScript({ key: 'value' })} | ||
</script>, | ||
]); | ||
}); | ||
|
||
it('removes data-react-helmet from title tag', () => { | ||
const title = <title data-react-helmet="true">Title</title>; | ||
|
||
expect(removeDataReactHelmetAttribute(title)).toStrictEqual( | ||
<title>Title</title>, | ||
); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/server/Document/Renderers/litePageTransforms/removeDataReactHelmetAttribute/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ReactElement } from 'react'; | ||
|
||
const getPropsExcludingDataReactHelmet = (props: object) => { | ||
return Object.fromEntries( | ||
Object.entries(props).filter(([key]) => key !== 'data-react-helmet'), | ||
); | ||
}; | ||
|
||
export default (tags: ReactElement | ReactElement[]) => { | ||
if (Array.isArray(tags)) { | ||
return tags.map(tag => { | ||
return { | ||
...tag, | ||
props: getPropsExcludingDataReactHelmet(tag.props), | ||
}; | ||
}); | ||
} | ||
|
||
return { | ||
...tags, | ||
props: getPropsExcludingDataReactHelmet(tags.props), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
ws-nextjs-app/integration/pages/live/gahuzaLiteSite/lite.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @service gahuza | ||
* @pathname /gahuza/live/c2dl5y6dgrzt | ||
*/ | ||
|
||
import { runLiteSiteTests } from '../../../../../src/integration/common'; | ||
|
||
describe('Lite Site', () => { | ||
describe(pageType, () => { | ||
runLiteSiteTests(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this perhaps be renamed to
removePlatform
instead?