Skip to content

Commit

Permalink
refactor(gatsby,gatsby-script): Misc review comments (#35710)
Browse files Browse the repository at this point in the history
refactor(gatsby,gatsby-script): Misc comments from Ward in #35403

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
tyhopp and pieh authored May 20, 2022
1 parent 191c557 commit f7f8ffe
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion packages/gatsby-script/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"presets": [["babel-preset-gatsby-package", { "browser": true }], "@babel/preset-typescript"]
"presets": [
["babel-preset-gatsby-package", { "browser": true, "esm": true }],
"@babel/preset-typescript"
]
}
6 changes: 2 additions & 4 deletions packages/gatsby-script/src/gatsby-script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function Script(props: ScriptProps): ReactElement | null {
})
break
case ScriptStrategy.offMainThread:
if (typeof window !== `undefined` && collectScript) {
if (collectScript) {
const attributes = resolveAttributes(props)
collectScript(attributes)
}
Expand Down Expand Up @@ -101,7 +101,6 @@ export function Script(props: ScriptProps): ReactElement | null {
return (
<script
type="text/partytown"
async
data-strategy={strategy}
crossOrigin="anonymous"
{...attributes}
Expand All @@ -112,7 +111,6 @@ export function Script(props: ScriptProps): ReactElement | null {
return (
<script
type="text/partytown"
async
src={proxyPartytownUrl(src)}
data-strategy={strategy}
crossOrigin="anonymous"
Expand Down Expand Up @@ -239,5 +237,5 @@ function proxyPartytownUrl(url: string | undefined): string | undefined {
if (!url) {
return undefined
}
return `/__partytown-proxy?url=${encodeURIComponent(url)}`
return `/__third-party-proxy?url=${encodeURIComponent(url)}`
}
4 changes: 2 additions & 2 deletions packages/gatsby/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { configureTrailingSlash } from "../utils/express-middlewares"
import { getDataStore, detectLmdbStore } from "../datastore"
import { functionMiddlewares } from "../internal-plugins/functions/middleware"
import {
partytownProxyPath,
thirdPartyProxyPath,
partytownProxy,
} from "../internal-plugins/partytown/proxy"

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

app.use(partytownProxyPath, partytownProxy(partytownProxiedURLs))
app.use(thirdPartyProxyPath, partytownProxy(partytownProxiedURLs))

// eslint-disable-next-line new-cap
const router = express.Router()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function PartytownProvider({ children }): ReactElement {
}
}
} else {
console.log(`unexpected shape of forward`, newScript)
if (process.env.NODE_ENV === `development`) {
console.log(`unexpected shape of forward`, newScript)
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/internal-plugins/partytown/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path"
import { copyLibFiles } from "@builder.io/partytown/utils"
import { CreateDevServerArgs } from "gatsby"
import { partytownProxyPath, partytownProxy } from "./proxy"
import { thirdPartyProxyPath, partytownProxy } from "./proxy"

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

createRedirect({
fromPath: `${partytownProxyPath}?url=${encodedURL}`,
fromPath: `${thirdPartyProxyPath}?url=${encodedURL}`,
toPath: encodedURL,
statusCode: 200,
})
Expand All @@ -40,5 +40,5 @@ export async function onCreateDevServer({
const { config } = store.getState()
const { partytownProxiedURLs = [] } = config || {}

app.use(partytownProxyPath, partytownProxy(partytownProxiedURLs))
app.use(thirdPartyProxyPath, partytownProxy(partytownProxiedURLs))
}
2 changes: 1 addition & 1 deletion packages/gatsby/src/internal-plugins/partytown/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import proxy from "express-http-proxy"
import type { RequestHandler } from "express"

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

export function partytownProxy(
partytownProxiedURLs: Array<string>
Expand Down

0 comments on commit f7f8ffe

Please sign in to comment.