-
-
Notifications
You must be signed in to change notification settings - Fork 751
fix(preview): fallback to server fetch when WASM query returns empty #3781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
64812db
46e1358
41709cc
6a1ca4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,18 @@ export function queryCollectionSearchSections<T extends keyof PageCollections>(c | |
|
|
||
| async function executeContentQuery<T extends keyof Collections, Result = Collections[T]>(event: H3Event | undefined, collection: T, sql: string) { | ||
| if (import.meta.client && window.WebAssembly) { | ||
| if (window.sessionStorage?.getItem('previewToken')) { | ||
| try { | ||
| const result = await queryContentSqlClientWasm<T, Result>(collection, sql) | ||
| if (result && (Array.isArray(result) ? result.length > 0 : true)) { | ||
| return result as Result[] | ||
| } | ||
| } | ||
| catch { | ||
| // WASM query failed — fall through to server fetch | ||
| } | ||
| return fetchQuery(event, String(collection), sql) as Promise<Result[]> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty-result fallback cannot distinguish "DB not synced" from "genuinely no matches". When WASM is fully synced and a preview-mode query legitimately returns zero results (e.g., filtering by a tag that matches no content), the condition on line 39 treats it identically to a missing-draft scenario and fires an extra There is no robust client-side signal to distinguish the two cases without additional metadata (e.g., a sync-complete flag written to 🤖 Prompt for AI Agents |
||
| } | ||
| return queryContentSqlClientWasm<T, Result>(collection, sql) as Promise<Result[]> | ||
| } | ||
| else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: nuxt/content
Length of output: 1053
🌐 Web query:
sessionStorage access throws error restricted browser context private browsing💡 Result:
Accessing sessionStorage throws errors like "Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document" or SecurityError/QuotaExceededError in restricted browser contexts, primarily due to privacy protections in private/incognito browsing or strict cookie settings.[1][2][3] Key causes: - Private browsing/incognito mode: Browsers restrict storage to prevent tracking. Data is session-only and cleared on close, but access may be limited.[4][5] Modern browsers (Chrome, Firefox, Safari post-2017) generally allow sessionStorage with reduced quotas (~5MB), but older Safari threw QuotaExceededError with 0 quota.[6][7][8] - Third-party/iframe contexts: Cross-origin iframes or embedded scripts (third-party) are blocked in incognito or when "Block third-party cookies" is enabled, especially Chrome.[9][10][11] - User-configured restrictions: Blocking cookies/site data interprets as "prevent persisting data," throwing SecurityError per spec.[1][2] - Other: Opaque origins (file:/data:), sandboxed iframes, enterprise policies.[1] Browser differences (as of 2026): - Chrome/Edge: Works in top-level incognito; fails in third-party iframes/incognito with cookie blocking.[9][10] - Firefox: Generally allows; some tab duplication quirks in private mode.[12] - Safari: Improved since Safari 11; now allows with quota limits in private mode.[6][7] Solution: Always wrap access in try-catch for graceful degradation. Use in-memory fallback.
try { sessionStorage.setItem('key', 'value'); } catch (e) { if (e.name === 'SecurityError' || e.name === 'QuotaExceededError') { // Fallback: in-memory storage, cookies, or disable features console.warn('sessionStorage unavailable; using fallback'); // e.g., const fallbackStorage = {}; } }Test availability first:function isStorageAvailable(type = 'sessionStorage') { try { const storage = window[type]; const test = 'storage_test'; storage.setItem(test, test); storage.removeItem(test); return true; } catch (e) { return false; } }For iframes/third-party, request Storage Access API if supported: document.requestStorageAccess({ sessionStorage: true }).[13][14] Users may need to adjust cookie settings for full access, but don't rely on it.[15][10]Citations:
Guard preview-token reads so fallback still works.
At Line 41,
sessionStorage.getItemis evaluated outside thetry. In restricted browser contexts (private browsing, third-party iframes, or cookie-blocking settings), this access can throwSecurityErrorand skip both the WASM path andfetchQueryfallback, causing the function to fail entirely.Proposed fix
🤖 Prompt for AI Agents