From 4c7f99ebf988979227717df6408d37be18014be9 Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Thu, 9 Mar 2023 06:09:32 -0800 Subject: [PATCH 1/7] chore: use charSet key --- packages/remix-react/components.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index e05cce6d42d..b5c4c4255ac 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -601,7 +601,7 @@ function V1Meta() { } if (["charset", "charSet"].includes(name)) { - return ; + return ; } if (name === "title") { @@ -727,7 +727,7 @@ function V2Meta() { // to do that? Seems like a nice convenience IMO. return ( ); From d0ecf7ba5133e0d85d69627a6b53c4c8845d2601 Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Thu, 9 Mar 2023 06:58:19 -0800 Subject: [PATCH 2/7] feat: add support for link tags and ld+json to v2 meta --- packages/remix-react/components.tsx | 49 ++++++++++++++++--- packages/remix-react/routeModules.ts | 11 ++++- packages/remix-server-runtime/routeModules.ts | 11 ++++- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index b5c4c4255ac..08c559a13c3 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -718,18 +718,49 @@ function V2Meta() { return null; } + if ("tagName" in metaProps) { + let tagName = metaProps.tagName; + delete metaProps.tagName; + if (!isValidMetaTag(tagName)) { + console.warn( + `A meta object uses an invalid tagName: ${tagName}. Expected either 'link' or 'meta'` + ); + return null; + } + let Comp = tagName; + return ; + } + if ("title" in metaProps) { return {String(metaProps.title)}; } - if ("charSet" in metaProps || "charset" in metaProps) { - // TODO: We normalize this for the user in v1, but should we continue - // to do that? Seems like a nice convenience IMO. + if ("charset" in metaProps) { + metaProps.charSet ??= metaProps.charset; + delete metaProps.charset; + } + + if ("charSet" in metaProps && metaProps.charSet != null) { + return typeof metaProps.charSet === "string" ? ( + + ) : null; + } + + if ("script:ld+json" in metaProps) { + let json: string | null = null; + try { + json = JSON.stringify(metaProps["script:ld+json"]); + } catch (err) {} return ( - + json != null && ( + ", "") + .trim(); + + expect(JSON.parse(scriptContents)).toEqual({ + "@context": "http://schema.org", + "@type": "Person", + name: "Sonny Day", + address: { + "@type": "PostalAddress", + streetAddress: "123 Sunset Cliffs Blvd", + addressLocality: "San Diego", + addressRegion: "CA", + postalCode: "92107", + }, + email: ["sonnyday@fancymail.com", "surfergal@veryprofessional.org"], + }); + }); + + test("{ tagName: 'link' } adds a ", async ({ page }) => { + let app = new PlaywrightFixture(appFixture, page); + await app.goto("/authors/1"); + expect(await app.getHtml('link[rel="canonical"]')).toBeTruthy(); + }); }); From 28676edf54a915b6d84ac059b2288cbddbe08236 Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Thu, 9 Mar 2023 14:12:09 -0800 Subject: [PATCH 4/7] add changeset --- .changeset/silly-birds-turn.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/silly-birds-turn.md diff --git a/.changeset/silly-birds-turn.md b/.changeset/silly-birds-turn.md new file mode 100644 index 00000000000..71354a264c3 --- /dev/null +++ b/.changeset/silly-birds-turn.md @@ -0,0 +1,6 @@ +--- +"@remix-run/react": minor +"@remix-run/server-runtime": patch +--- + +Add support for generating `