Skip to content

Commit 50d067d

Browse files
authored
fix: scripts: remove double scripts injection (#5486)
1 parent e0a010d commit 50d067d

File tree

19 files changed

+114
-220
lines changed

19 files changed

+114
-220
lines changed

gatsby-config.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const keywords = [
1717
'models management'
1818
]
1919

20+
const siteUrl = process.env.HEROKU_APP_NAME
21+
? `https://${process.env.HEROKU_APP_NAME}.herokuapp.com/`
22+
: 'https://doc.dvc.org'
23+
2024
const plugins = [
2125
{
2226
resolve: '@dvcorg/gatsby-theme',
@@ -104,6 +108,23 @@ const plugins = [
104108
}
105109
]
106110

111+
// keep usercentrics plugin before plausible
112+
let usercentricsSettingsId = process.env.GATSBY_USERCENTRICS_SETTINGS_ID
113+
if (usercentricsSettingsId) {
114+
plugins.push({
115+
resolve: 'gatsby-plugin-usercentrics',
116+
options: { settingsId: usercentricsSettingsId }
117+
})
118+
}
119+
plugins.push({
120+
resolve: 'gatsby-plugin-plausible',
121+
options: {
122+
domain: new URL(siteUrl).hostname,
123+
apiEndpoint: '/pl/api/event',
124+
scriptSrc: '/pl/js/plausible.outbound-links.js'
125+
}
126+
})
127+
107128
if (process.env.GATSBY_GTM_ID) {
108129
plugins.push({
109130
resolve: `gatsby-plugin-google-tagmanager`,
@@ -139,9 +160,7 @@ module.exports = {
139160
description,
140161
author: 'Iterative',
141162
keywords,
142-
siteUrl: process.env.HEROKU_APP_NAME
143-
? `https://${process.env.HEROKU_APP_NAME}.herokuapp.com/`
144-
: 'https://doc.dvc.org',
163+
siteUrl,
145164
title
146165
},
147166
developMiddleware: app => {

gatsby-ssr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* eslint-env node */
12
export { wrapPageElement } from './gatsby-shared'

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"react": "18.3.1",
7777
"react-collapse": "5.1.1",
7878
"react-dom": "18.3.1",
79-
"react-helmet": "6.1.0",
8079
"react-instantsearch-dom": "6.40.4",
8180
"serve-handler": "6.1.6",
8281
"tailwind-merge": "3.3.1",
@@ -98,7 +97,6 @@
9897
"@types/promise-polyfill": "6.0.6",
9998
"@types/react": "18.3.26",
10099
"@types/react-collapse": "5.0.4",
101-
"@types/react-helmet": "6.1.11",
102100
"@types/react-instantsearch-dom": "6.12.9",
103101
"@types/react-popover": "0.5.8",
104102
"babel-jest": "30.2.0",
@@ -113,7 +111,6 @@
113111
"eslint-plugin-prettier": "5.5.4",
114112
"eslint-plugin-react": "7.37.5",
115113
"eslint-plugin-react-hooks": "5.2.0",
116-
"gatsby-plugin-react-helmet": "6.15.0",
117114
"gatsby-plugin-webpack-bundle-analyser-v2": "1.1.32",
118115
"gatsby-source-filesystem": "5.15.0",
119116
"globals": "16.4.0",

packages/gatsby-theme/gatsby-config.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const imageMaxWidth = 700
1919

2020
module.exports = ({
2121
simpleLinkerTerms,
22-
plausibleSrc = '/pl/js/plausible.outbound-links.js',
23-
plausibleAPI = '/pl/api/event',
24-
plausibleDomain,
2522
postCssPlugins = [
2623
require('tailwindcss/nesting')(require('postcss-nested')),
2724
autoprefixer,
@@ -41,7 +38,6 @@ module.exports = ({
4138
postCssPlugins
4239
}
4340
},
44-
'gatsby-plugin-react-helmet',
4541
'gatsby-plugin-sitemap',
4642
glossaryInstanceName && {
4743
resolve: 'gatsby-source-filesystem',
@@ -166,10 +162,7 @@ module.exports = ({
166162
author: 'Iterative',
167163
titleTemplate: '',
168164
twitterUsername: '',
169-
imageAlt: '',
170-
plausibleSrc,
171-
plausibleAPI,
172-
plausibleDomain
165+
imageAlt: ''
173166
},
174167
trailingSlash: 'never',
175168
jsxRuntime: 'automatic'

packages/gatsby-theme/gatsby-node.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ exports.pluginOptionsSchema = ({ Joi }) => {
3838
argsLinkerPath: Joi.alternatives()
3939
.try(Joi.string(), Joi.array().items(Joi.string()))
4040
.default(defaults.argsLinkerPath),
41-
plausibleSrc: [Joi.string().optional(), Joi.allow(null)],
42-
plausibleAPI: [Joi.string().optional(), Joi.allow(null)],
43-
plausibleDomain: [Joi.string().optional(), Joi.allow(null)],
4441
sentry: Joi.boolean().default(defaults.sentry)
4542
})
4643
}
@@ -78,10 +75,7 @@ exports.createSchemaCustomization = async api => {
7875
fields: {
7976
author: 'String',
8077
siteUrl: 'String',
81-
titleTemplate: 'String',
82-
plausibleSrc: 'String',
83-
plausibleDomain: 'String',
84-
plausibleAPI: 'String'
78+
titleTemplate: 'String'
8579
}
8680
})
8781
])

packages/gatsby-theme/gatsby-ssr.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/gatsby-theme/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"gatsby-plugin-image": "3.15.0",
2222
"gatsby-plugin-manifest": "5.15.0",
2323
"gatsby-plugin-postcss": "6.15.0",
24-
"gatsby-plugin-react-helmet": "6.15.0",
2524
"gatsby-plugin-sharp": "5.15.0",
2625
"gatsby-plugin-sitemap": "6.15.0",
2726
"gatsby-plugin-svgr": "3.0.0-beta.0",
@@ -50,7 +49,6 @@
5049
"promise-polyfill": "8.3.0",
5150
"react-collapse": "5.1.1",
5251
"react-collapsible": "2.10.0",
53-
"react-helmet": "6.1.0",
5452
"react-intersection-observer": "9.16.0",
5553
"rehype-parse": "9.0.1",
5654
"rehype-react": "7.2.0",
@@ -73,7 +71,6 @@
7371
"@types/isomorphic-fetch": "0.0.39",
7472
"@types/promise-polyfill": "6.0.6",
7573
"@types/react-collapse": "5.0.4",
76-
"@types/react-helmet": "6.1.11",
7774
"@types/unist": "3.0.3",
7875
"stylelint": "16.25.0",
7976
"typescript": "5.9.3"

packages/gatsby-theme/src/components/MainLayout/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import cn from 'classnames'
2-
import { PageProps } from 'gatsby'
32
import { ReactNode, useEffect } from 'react'
43

54
import 'reset-css'
@@ -8,7 +7,6 @@ import './fonts.css'
87
import { handleFirstTab } from '../../utils/front/accessibility'
98
import LayoutFooter from '../LayoutFooter'
109
import LayoutHeader from '../LayoutHeader'
11-
import SEO from '../SEO'
1210

1311
import { useRedirects } from './utils'
1412

@@ -23,16 +21,14 @@ export interface ILayoutModifiable {
2321
}
2422

2523
export interface ILayoutComponentProps extends ILayoutModifiable {
26-
location: PageProps['location']
2724
className?: string
2825
children?: ReactNode
2926
}
3027

3128
const MainLayout = ({
3229
className,
3330
children,
34-
modifiers = [],
35-
location
31+
modifiers = []
3632
}: ILayoutComponentProps) => {
3733
useRedirects()
3834

@@ -55,7 +51,6 @@ const MainLayout = ({
5551
'items-center'
5652
)}
5753
>
58-
<SEO pathname={location.pathname} />
5954
<LayoutHeader modifiers={modifiers} />
6055
<main
6156
className={cn(

packages/gatsby-theme/src/components/SEO/index.tsx

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,40 @@
11
import { IGatsbyImageData } from 'gatsby-plugin-image'
22
import { useMemo } from 'react'
3-
import { Helmet } from 'react-helmet'
43

54
import useSiteMeta from '../../queries/useSiteMeta'
65

7-
import { buildMetadata, MetaProps, LinkProps } from './helper'
6+
import { buildMetadata } from './helper'
87

98
export interface IPaginatorPageInfo {
109
currentPage: number
1110
nextPage?: string
1211
previousPage?: string
1312
}
1413

15-
interface ISEOProps {
14+
export interface ISEOProps {
1615
title?: string
1716
defaultMetaTitle?: boolean
18-
skipTitleTemplate?: boolean
1917
description?: string
2018
keywords?: string
2119
imageAlt?: string
2220
image?: IGatsbyImageData | string
2321
imageHeight?: number
2422
imageWidth?: number
25-
meta?: MetaProps[]
26-
link?: LinkProps[]
2723
canonicalUrl?: string
2824
pathname?: string
2925
pageInfo?: IPaginatorPageInfo
3026
children?: React.ReactNode
3127
}
3228

33-
const GATSBY_USERCENTRICS_SETTINGS_ID =
34-
process.env.GATSBY_USERCENTRICS_SETTINGS_ID
35-
3629
const SEO: React.FC<ISEOProps> = ({
3730
title,
3831
defaultMetaTitle,
39-
skipTitleTemplate,
4032
description,
4133
keywords,
4234
image = '/social-share.png',
4335
imageAlt = '',
4436
imageHeight = 630,
4537
imageWidth = 1200,
46-
meta = [],
47-
link = [],
4838
canonicalUrl,
4939
pathname,
5040
pageInfo,
@@ -84,63 +74,19 @@ const SEO: React.FC<ISEOProps> = ({
8474
imageHeight,
8575
pathname
8676
])
87-
77+
const canonical = canonicalUrl || fullUrl
8878
return (
89-
/* @ts-expect-error react-helmet types incompatible with React types */
90-
<Helmet
91-
htmlAttributes={{
92-
lang: 'en'
93-
}}
94-
defaultTitle={siteMeta.title}
95-
title={pageTitle}
96-
titleTemplate={
97-
skipTitleTemplate
98-
? ''
99-
: siteMeta.titleTemplate || `%s | ${siteMeta.title}`
100-
}
101-
meta={[...prebuildMeta, ...meta]}
102-
link={[
103-
...(canonicalUrl
104-
? [
105-
{
106-
rel: 'canonical',
107-
href: canonicalUrl
108-
}
109-
]
110-
: pathname
111-
? [
112-
{
113-
rel: 'canonical',
114-
href: fullUrl
115-
}
116-
]
117-
: []),
118-
...link
119-
]}
120-
>
121-
{GATSBY_USERCENTRICS_SETTINGS_ID && (
122-
<script src="https://web.cmp.usercentrics.eu/modules/autoblocker.js" />
123-
)}
124-
{GATSBY_USERCENTRICS_SETTINGS_ID && (
125-
<script
126-
id="usercentrics-cmp"
127-
src="https://web.cmp.usercentrics.eu/ui/loader.js"
128-
data-settings-id={GATSBY_USERCENTRICS_SETTINGS_ID}
129-
async
130-
/>
131-
)}
132-
{siteMeta.plausibleSrc ? (
133-
<script
134-
defer
135-
data-domain={
136-
siteMeta.plausibleDomain || new URL(siteMeta.siteUrl).hostname
137-
}
138-
data-api={siteMeta.plausibleAPI || undefined}
139-
src={siteMeta.plausibleSrc}
140-
/>
141-
) : null}
79+
<>
80+
<html lang="en" />
81+
{canonical && <link rel="canonical" href={canonical} />}
82+
<title>
83+
{pageTitle ? `${pageTitle} | ${siteMeta.title}` : siteMeta.title}
84+
</title>
85+
{prebuildMeta.map((m, i) => (
86+
<meta key={i} {...m} />
87+
))}
14288
{children}
143-
</Helmet>
89+
</>
14490
)
14591
}
14692

packages/gatsby-theme/src/queries/useSiteMeta.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ interface ISiteMeta {
77
siteUrl: string
88
titleTemplate: string
99
imageAlt?: string
10-
plausibleDomain: string | null
11-
plausibleSrc: string | null
12-
plausibleAPI: string | null
1310
twitterUsername?: string
1411
}
1512

@@ -26,9 +23,6 @@ export default function useSiteMeta(): ISiteMeta {
2623
siteUrl
2724
titleTemplate
2825
imageAlt
29-
plausibleDomain
30-
plausibleSrc
31-
plausibleAPI
3226
twitterUsername
3327
}
3428
}

0 commit comments

Comments
 (0)