Skip to content

Commit f7f8ffe

Browse files
tyhopppieh
andauthored
refactor(gatsby,gatsby-script): Misc review comments (#35710)
refactor(gatsby,gatsby-script): Misc comments from Ward in #35403 Co-authored-by: Michal Piechowiak <[email protected]>
1 parent 191c557 commit f7f8ffe

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

packages/gatsby-script/.babelrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"presets": [["babel-preset-gatsby-package", { "browser": true }], "@babel/preset-typescript"]
2+
"presets": [
3+
["babel-preset-gatsby-package", { "browser": true, "esm": true }],
4+
"@babel/preset-typescript"
5+
]
36
}

packages/gatsby-script/src/gatsby-script.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function Script(props: ScriptProps): ReactElement | null {
6767
})
6868
break
6969
case ScriptStrategy.offMainThread:
70-
if (typeof window !== `undefined` && collectScript) {
70+
if (collectScript) {
7171
const attributes = resolveAttributes(props)
7272
collectScript(attributes)
7373
}
@@ -101,7 +101,6 @@ export function Script(props: ScriptProps): ReactElement | null {
101101
return (
102102
<script
103103
type="text/partytown"
104-
async
105104
data-strategy={strategy}
106105
crossOrigin="anonymous"
107106
{...attributes}
@@ -112,7 +111,6 @@ export function Script(props: ScriptProps): ReactElement | null {
112111
return (
113112
<script
114113
type="text/partytown"
115-
async
116114
src={proxyPartytownUrl(src)}
117115
data-strategy={strategy}
118116
crossOrigin="anonymous"
@@ -239,5 +237,5 @@ function proxyPartytownUrl(url: string | undefined): string | undefined {
239237
if (!url) {
240238
return undefined
241239
}
242-
return `/__partytown-proxy?url=${encodeURIComponent(url)}`
240+
return `/__third-party-proxy?url=${encodeURIComponent(url)}`
243241
}

packages/gatsby/src/commands/serve.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { configureTrailingSlash } from "../utils/express-middlewares"
2626
import { getDataStore, detectLmdbStore } from "../datastore"
2727
import { functionMiddlewares } from "../internal-plugins/functions/middleware"
2828
import {
29-
partytownProxyPath,
29+
thirdPartyProxyPath,
3030
partytownProxy,
3131
} from "../internal-plugins/partytown/proxy"
3232

@@ -127,7 +127,7 @@ module.exports = async (program: IServeProgram): Promise<void> => {
127127
// Proxy gatsby-script using off-main-thread strategy
128128
const { partytownProxiedURLs = [] } = config || {}
129129

130-
app.use(partytownProxyPath, partytownProxy(partytownProxiedURLs))
130+
app.use(thirdPartyProxyPath, partytownProxy(partytownProxiedURLs))
131131

132132
// eslint-disable-next-line new-cap
133133
const router = express.Router()

packages/gatsby/src/internal-plugins/partytown/gatsby-browser.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function PartytownProvider({ children }): ReactElement {
3939
}
4040
}
4141
} else {
42-
console.log(`unexpected shape of forward`, newScript)
42+
if (process.env.NODE_ENV === `development`) {
43+
console.log(`unexpected shape of forward`, newScript)
44+
}
4345
}
4446
}
4547

packages/gatsby/src/internal-plugins/partytown/gatsby-node.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path"
22
import { copyLibFiles } from "@builder.io/partytown/utils"
33
import { CreateDevServerArgs } from "gatsby"
4-
import { partytownProxyPath, partytownProxy } from "./proxy"
4+
import { thirdPartyProxyPath, partytownProxy } from "./proxy"
55

66
/**
77
* Copy Partytown library files to public.
@@ -26,7 +26,7 @@ exports.createPages = ({ actions, store }): void => {
2626
const encodedURL: string = encodeURI(host)
2727

2828
createRedirect({
29-
fromPath: `${partytownProxyPath}?url=${encodedURL}`,
29+
fromPath: `${thirdPartyProxyPath}?url=${encodedURL}`,
3030
toPath: encodedURL,
3131
statusCode: 200,
3232
})
@@ -40,5 +40,5 @@ export async function onCreateDevServer({
4040
const { config } = store.getState()
4141
const { partytownProxiedURLs = [] } = config || {}
4242

43-
app.use(partytownProxyPath, partytownProxy(partytownProxiedURLs))
43+
app.use(thirdPartyProxyPath, partytownProxy(partytownProxiedURLs))
4444
}

packages/gatsby/src/internal-plugins/partytown/proxy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import proxy from "express-http-proxy"
22
import type { RequestHandler } from "express"
33

4-
export const partytownProxyPath = `/__partytown-proxy`
4+
export const thirdPartyProxyPath = `/__third-party-proxy`
55

66
export function partytownProxy(
77
partytownProxiedURLs: Array<string>

0 commit comments

Comments
 (0)