mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 01:39:47 +00:00
[bugfix] fix service worker opaqueredirect error and ensure SW controls page before mount (#6275)
Fixes service worker network error by handling opaqueredirect responses correctly and ensures SW registration completes before app mount to prevent race conditions on first load. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6275-bugfix-fix-service-worker-opaqueredirect-error-and-ensure-SW-controls-page-before-mount-2976d73d36508106bc65dc82cdc62779) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -67,15 +67,28 @@ self.addEventListener('fetch', (event) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// If redirected to external storage (GCS), follow without auth headers
|
// Handle redirects to external storage (e.g., GCS signed URLs)
|
||||||
// The signed URL contains its own authentication in query params
|
if (response.type === 'opaqueredirect') {
|
||||||
if (
|
// Opaqueredirect: redirect occurred but response is opaque (headers not accessible)
|
||||||
response.type === 'opaqueredirect' ||
|
// Re-fetch the original /api/view URL with redirect: 'follow'
|
||||||
response.status === 302 ||
|
// Browser will:
|
||||||
response.status === 301
|
// 1. Send auth headers to /api/view (same-origin)
|
||||||
) {
|
// 2. Receive 302 redirect to GCS
|
||||||
|
// 3. Automatically strip auth headers when following cross-origin redirect
|
||||||
|
// 4. Use GCS signed URL authentication instead
|
||||||
|
return fetch(event.request.url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: headers,
|
||||||
|
redirect: 'follow'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-opaque redirect (status visible) - shouldn't normally happen with redirect: 'manual'
|
||||||
|
// but handle as fallback
|
||||||
|
if (response.status === 302 || response.status === 301) {
|
||||||
const location = response.headers.get('location')
|
const location = response.headers.get('location')
|
||||||
if (location) {
|
if (location) {
|
||||||
|
// Follow redirect manually - do NOT include auth headers for external URLs
|
||||||
return fetch(location, {
|
return fetch(location, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
redirect: 'follow'
|
redirect: 'follow'
|
||||||
|
|||||||
@@ -83,8 +83,9 @@ app
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Register auth service worker after Pinia is initialized (cloud-only)
|
// Register auth service worker after Pinia is initialized (cloud-only)
|
||||||
|
// Wait for registration to complete before mounting to ensure SW controls the page
|
||||||
if (isCloud) {
|
if (isCloud) {
|
||||||
void import('@/platform/auth/serviceWorker')
|
await import('@/platform/auth/serviceWorker')
|
||||||
}
|
}
|
||||||
|
|
||||||
app.mount('#vue-app')
|
app.mount('#vue-app')
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ import { isCloud } from '@/platform/distribution/types'
|
|||||||
* Tree-shaken for desktop/localhost builds via compile-time constant.
|
* Tree-shaken for desktop/localhost builds via compile-time constant.
|
||||||
*/
|
*/
|
||||||
if (isCloud) {
|
if (isCloud) {
|
||||||
void import('./register')
|
await import('./register')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,4 +54,4 @@ function setupCacheInvalidation(): void {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerAuthServiceWorker()
|
await registerAuthServiceWorker()
|
||||||
|
|||||||
Reference in New Issue
Block a user