authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 00:18:47-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 00:18:47-07:00
logaca2afc0b5400e4cf88c42d59b214240833ed9cd
tree89bab6e9f76cd7a1776e82da1f6bdb820e6fda61
parent94d1fa7ff268e88476a341eb73f9f032e2af6a21
signature Signed by PGP key B5690EEEBB952194

refactor(shared): remove unused preview URL predicate (#9989)


2 files changed, 0 insertions(+), 30 deletions(-)

packages/shared/src/preview.test.ts-19
......@@ -2,7 +2,6 @@ import { describe, expect, it } from "vite-plus/test";
22
33import {
44 isLoopbackHost,
5 isPreviewableUrl,
65 newPreviewTabId,
76 normalizePreviewUrl,
87 PreviewUrlNormalizationError,
......@@ -27,24 +26,6 @@ describe("isLoopbackHost", () => {
2726 });
2827});
2928
30describe("isPreviewableUrl", () => {
31 it.each([
32 "http://localhost:5173",
33 "http://127.0.0.1:3000/path",
34 "http://0.0.0.0:8080",
35 "http://[::1]:5173",
36 ])("%s is previewable", (url) => {
37 expect(isPreviewableUrl(url)).toBe(true);
38 });
39
40 it.each(["https://example.com", "ws://localhost:5173", "file:///etc/passwd", "not-a-url", ""])(
41 "%s is not previewable",
42 (url) => {
43 expect(isPreviewableUrl(url)).toBe(false);
44 },
45 );
46});
47
4829describe("normalizePreviewUrl", () => {
4930 it("treats bare loopback hosts as http", () => {
5031 expect(normalizePreviewUrl("localhost:5173")).toBe("http://localhost:5173/");
packages/shared/src/preview.ts-11
......@@ -36,17 +36,6 @@ export function isLoopbackHost(host: string): boolean {
3636 return false;
3737}
3838
39/** True when a raw URL string looks like a loopback dev URL we can preview. */
40export function isPreviewableUrl(rawUrl: string): boolean {
41 try {
42 const parsed = new URL(rawUrl);
43 if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
44 return isLoopbackHost(parsed.hostname);
45 } catch {
46 return false;
47 }
48}
49
5039export class PreviewUrlNormalizationError extends Schema.TaggedErrorClass<PreviewUrlNormalizationError>()(
5140 "PreviewUrlNormalizationError",
5241 {