Skip to content

Commit c932020

Browse files
authoredMar 4, 2025
feat: set bridge script based on ENV & add data-attribute (#8830)
1 parent 7b50266 commit c932020

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

‎packages/sanity/src/_internal/cli/server/renderDocument.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,21 @@ export function decorateIndexWithAutoGeneratedWarning(template: string): string
125125
* with core-ui.
126126
*/
127127
export function decorateIndexWithBridgeScript(template: string): string {
128+
const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production'
129+
130+
/**
131+
* The URL to the bridge script is determined by the
132+
* `SANITY_INTERNAL_ENV` environment variable. So if you deploy
133+
* a studio to the staging ENV then you'll get the correct script.
134+
*/
135+
const scriptURL =
136+
sanityEnv === 'production'
137+
? 'https://core.sanity-cdn.com/bridge.js'
138+
: 'https://core.sanity-cdn.work/bridge.js'
139+
128140
return template.replace(
129141
'</head>',
130-
'<script src="https://core.sanity-cdn.com/bridge.js" async type="module"></script>\n</head>',
142+
`<script src="${scriptURL}" async type="module" data-sanity-core></script>\n</head>`,
131143
)
132144
}
133145

0 commit comments

Comments
 (0)