Skip to content

feat: remove trailing slash from void elements #232

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/server/__snapshots__/base.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`server > API > renders base tag as React component 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\"/>"`;

exports[`server > API > renders base tags as string 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\"/>"`;
exports[`server > API > renders base tags as string 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\">"`;

exports[`server > Declarative API > renders base tag as React component 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\"/>"`;

exports[`server > Declarative API > renders base tags as string 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\"/>"`;
exports[`server > Declarative API > renders base tags as string 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\">"`;
8 changes: 4 additions & 4 deletions __tests__/server/__snapshots__/helmetData.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ exports[`Helmet Data > browser > renders without context 1`] = `"<base target=\\

exports[`Helmet Data > browser > sets base tag based on deepest nested component 1`] = `"<base href=\\"http://mysite.com/public\\" data-rh=\\"true\\">"`;

exports[`Helmet Data > server > renders declarative without context 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\"/>"`;
exports[`Helmet Data > server > renders declarative without context 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\">"`;

exports[`Helmet Data > server > renders without context 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\"/>"`;
exports[`Helmet Data > server > renders without context 1`] = `"<base data-rh=\\"true\\" target=\\"_blank\\" href=\\"http://localhost/\\">"`;

exports[`Helmet Data > server > sets base tag based on deepest nested component 1`] = `"<base data-rh=\\"true\\" href=\\"http://mysite.com/public\\"/>"`;
exports[`Helmet Data > server > sets base tag based on deepest nested component 1`] = `"<base data-rh=\\"true\\" href=\\"http://mysite.com/public\\">"`;

exports[`Helmet Data > server > works with the same context object but separate HelmetData instances 1`] = `"<base data-rh=\\"true\\" href=\\"http://mysite.com/public\\"/>"`;
exports[`Helmet Data > server > works with the same context object but separate HelmetData instances 1`] = `"<base data-rh=\\"true\\" href=\\"http://mysite.com/public\\">"`;
4 changes: 2 additions & 2 deletions __tests__/server/__snapshots__/link.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`server > API > renders link tags as React components 1`] = `"<link data-rh=\\"true\\" href=\\"http://localhost/helmet\\" rel=\\"canonical\\"/><link data-rh=\\"true\\" href=\\"http://localhost/style.css\\" rel=\\"stylesheet\\" type=\\"text/css\\"/>"`;

exports[`server > API > renders link tags as string 1`] = `"<link data-rh=\\"true\\" href=\\"http://localhost/helmet\\" rel=\\"canonical\\"/><link data-rh=\\"true\\" href=\\"http://localhost/style.css\\" rel=\\"stylesheet\\" type=\\"text/css\\"/>"`;
exports[`server > API > renders link tags as string 1`] = `"<link data-rh=\\"true\\" href=\\"http://localhost/helmet\\" rel=\\"canonical\\"><link data-rh=\\"true\\" href=\\"http://localhost/style.css\\" rel=\\"stylesheet\\" type=\\"text/css\\">"`;

exports[`server > Declarative API > renders link tags as React components 1`] = `"<link data-rh=\\"true\\" href=\\"http://localhost/helmet\\" rel=\\"canonical\\"/><link data-rh=\\"true\\" href=\\"http://localhost/style.css\\" rel=\\"stylesheet\\" type=\\"text/css\\"/>"`;

exports[`server > Declarative API > renders link tags as string 1`] = `"<link data-rh=\\"true\\" href=\\"http://localhost/helmet\\" rel=\\"canonical\\"/><link data-rh=\\"true\\" href=\\"http://localhost/style.css\\" rel=\\"stylesheet\\" type=\\"text/css\\"/>"`;
exports[`server > Declarative API > renders link tags as string 1`] = `"<link data-rh=\\"true\\" href=\\"http://localhost/helmet\\" rel=\\"canonical\\"><link data-rh=\\"true\\" href=\\"http://localhost/style.css\\" rel=\\"stylesheet\\" type=\\"text/css\\">"`;
4 changes: 2 additions & 2 deletions __tests__/server/__snapshots__/meta.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`server > API > renders meta tags as React components 1`] = `"<meta data-rh=\\"true\\" charSet=\\"utf-8\\"/><meta data-rh=\\"true\\" name=\\"description\\" content=\\"Test description &amp; encoding of special characters like &#x27; &quot; &gt; &lt; \`\\"/><meta data-rh=\\"true\\" http-equiv=\\"content-type\\" content=\\"text/html\\"/><meta data-rh=\\"true\\" property=\\"og:type\\" content=\\"article\\"/><meta data-rh=\\"true\\" itemProp=\\"name\\" content=\\"Test name itemprop\\"/>"`;

exports[`server > API > renders meta tags as string 1`] = `"<meta data-rh=\\"true\\" charset=\\"utf-8\\"/><meta data-rh=\\"true\\" name=\\"description\\" content=\\"Test description &amp; encoding of special characters like &#x27; &quot; &gt; &lt; \`\\"/><meta data-rh=\\"true\\" http-equiv=\\"content-type\\" content=\\"text/html\\"/><meta data-rh=\\"true\\" property=\\"og:type\\" content=\\"article\\"/><meta data-rh=\\"true\\" itemprop=\\"name\\" content=\\"Test name itemprop\\"/>"`;
exports[`server > API > renders meta tags as string 1`] = `"<meta data-rh=\\"true\\" charset=\\"utf-8\\"><meta data-rh=\\"true\\" name=\\"description\\" content=\\"Test description &amp; encoding of special characters like &#x27; &quot; &gt; &lt; \`\\"><meta data-rh=\\"true\\" http-equiv=\\"content-type\\" content=\\"text/html\\"><meta data-rh=\\"true\\" property=\\"og:type\\" content=\\"article\\"><meta data-rh=\\"true\\" itemprop=\\"name\\" content=\\"Test name itemprop\\">"`;

exports[`server > Declarative API > renders meta tags as React components 1`] = `"<meta data-rh=\\"true\\" charSet=\\"utf-8\\"/><meta data-rh=\\"true\\" name=\\"description\\" content=\\"Test description &amp; encoding of special characters like &#x27; &quot; &gt; &lt; \`\\"/><meta data-rh=\\"true\\" http-equiv=\\"content-type\\" content=\\"text/html\\"/><meta data-rh=\\"true\\" property=\\"og:type\\" content=\\"article\\"/><meta data-rh=\\"true\\" itemProp=\\"name\\" content=\\"Test name itemprop\\"/>"`;

exports[`server > Declarative API > renders meta tags as string 1`] = `"<meta data-rh=\\"true\\" charset=\\"utf-8\\"/><meta data-rh=\\"true\\" name=\\"description\\" content=\\"Test description &amp; encoding of special characters like &#x27; &quot; &gt; &lt; \`\\"/><meta data-rh=\\"true\\" http-equiv=\\"content-type\\" content=\\"text/html\\"/><meta data-rh=\\"true\\" property=\\"og:type\\" content=\\"article\\"/><meta data-rh=\\"true\\" itemprop=\\"name\\" content=\\"Test name itemprop\\"/>"`;
exports[`server > Declarative API > renders meta tags as string 1`] = `"<meta data-rh=\\"true\\" charset=\\"utf-8\\"><meta data-rh=\\"true\\" name=\\"description\\" content=\\"Test description &amp; encoding of special characters like &#x27; &quot; &gt; &lt; \`\\"><meta data-rh=\\"true\\" http-equiv=\\"content-type\\" content=\\"text/html\\"><meta data-rh=\\"true\\" property=\\"og:type\\" content=\\"article\\"><meta data-rh=\\"true\\" itemprop=\\"name\\" content=\\"Test name itemprop\\">"`;
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const generateTagsAsString = (type: string, tags: HTMLElement[], encode = true)
const isSelfClosing = SELF_CLOSING_TAGS.indexOf(type) === -1;

return `${str}<${type} ${HELMET_ATTRIBUTE}="true" ${attributeHtml}${
isSelfClosing ? `/>` : `>${tagContent}</${type}>`
isSelfClosing ? `>` : `>${tagContent}</${type}>`
}`;
}, '');

Expand Down