Skip to content

Commit e11f62e

Browse files
authored
fix(playground): use localhost if on localhost (#12227)
When running on localhost use localhost for playground urls.
1 parent 4cc84ca commit e11f62e

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Diff for: client/src/playground/index.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,13 @@ export default function Playground() {
127127

128128
// We're using a random subdomain for origin isolation.
129129
const url = new URL(
130-
`${window.location.protocol}//${
131-
PLAYGROUND_BASE_HOST.startsWith("localhost")
132-
? ""
133-
: `${subdomain.current}.`
134-
}${PLAYGROUND_BASE_HOST}`
130+
window.location.hostname.endsWith("localhost")
131+
? window.location.origin
132+
: `${window.location.protocol}//${
133+
PLAYGROUND_BASE_HOST.startsWith("localhost")
134+
? ""
135+
: `${subdomain.current}.`
136+
}${PLAYGROUND_BASE_HOST}`
135137
);
136138
setVConsole([]);
137139
url.searchParams.set("state", state);

Diff for: client/src/playground/utils.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ export async function initPlayIframe(
3535
JSON.stringify(editorContent)
3636
);
3737
const path = iframe.getAttribute("data-live-path");
38-
const host = PLAYGROUND_BASE_HOST.startsWith("localhost")
39-
? PLAYGROUND_BASE_HOST
40-
: `${hash}.${PLAYGROUND_BASE_HOST}`;
4138
const url = new URL(
4239
`${path || ""}${path?.endsWith("/") ? "" : "/"}runner.html`,
4340
window.location.origin
4441
);
45-
url.port = "";
46-
url.host = host;
42+
if (!window.location.hostname.endsWith("localhost")) {
43+
const host = PLAYGROUND_BASE_HOST.startsWith("localhost")
44+
? PLAYGROUND_BASE_HOST
45+
: `${hash}.${PLAYGROUND_BASE_HOST}`;
46+
url.port = "";
47+
url.host = host;
48+
}
4749
url.search = "";
4850
url.searchParams.set("state", state);
4951
iframe.src = url.href;

Diff for: client/src/setupProxy.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function config(app) {
2020
app.use(`**/*.(gif|jpeg|jpg|mp3|mp4|ogg|png|svg|webm|webp|woff2)`, proxy);
2121
// All those root-level images like /favicon-48x48.png
2222
app.use("/*.(png|webp|gif|jpe?g|svg)", proxy);
23+
// Proxy play runner
24+
app.use("/**/runner.html", proxy);
2325
}
2426

2527
export default config;

0 commit comments

Comments
 (0)