Skip to content

Commit c3b5904

Browse files
Fix Safari: explicitly resolve URLs against base
Safari's fetch() doesn't respect the <base> tag. Use document.baseURI to resolve relative URLs explicitly.
1 parent e177415 commit c3b5904

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

frontend/app/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ export default function Dashboard() {
3535
}
3636
}
3737

38+
// Helper to resolve URLs against base (Safari doesn't respect <base> for fetch)
39+
const resolveUrl = (path: string) => {
40+
const base = document.baseURI || window.location.href
41+
return new URL(path, base).href
42+
}
43+
3844
// Load image list
3945
useEffect(() => {
4046
async function loadImageList() {
4147
try {
42-
const response = await fetch('image-list.json')
48+
const response = await fetch(resolveUrl('image-list.json'))
4349
if (response.ok) {
4450
const data = await response.json()
4551
const imageList: ImageData[] = data.images.map((imageName: string) => ({
@@ -108,7 +114,7 @@ export default function Dashboard() {
108114
async function loadAnnotationsForImage(imageId: string) {
109115
setImageLoading(true)
110116
try {
111-
const response = await fetch(`annotations/nsd/${imageId}_annotations.json`)
117+
const response = await fetch(resolveUrl(`annotations/nsd/${imageId}_annotations.json`))
112118
if (response.ok) {
113119
const data = await response.json()
114120
setAnnotations(prev => ({ ...prev, [imageId]: data.annotations || [] }))

0 commit comments

Comments
 (0)