From 1ef14ba85983c70f9dc6e1d0d9c4a9c46420c5e9 Mon Sep 17 00:00:00 2001 From: Varixo Date: Thu, 9 Jan 2025 17:20:15 +0100 Subject: [PATCH] feat: log a warning instead of throwing an error for server host mismatch error --- .changeset/shaggy-poems-appear.md | 5 +++ packages/qwik/src/core/shared/error/error.ts | 14 ++++---- packages/qwik/src/core/shared/scheduler.ts | 34 ++++---------------- 3 files changed, 17 insertions(+), 36 deletions(-) create mode 100644 .changeset/shaggy-poems-appear.md diff --git a/.changeset/shaggy-poems-appear.md b/.changeset/shaggy-poems-appear.md new file mode 100644 index 00000000000..4899a30fc83 --- /dev/null +++ b/.changeset/shaggy-poems-appear.md @@ -0,0 +1,5 @@ +--- +'@qwik.dev/core': patch +--- + +feat: log a warning instead of throwing an error for server host mismatch error diff --git a/packages/qwik/src/core/shared/error/error.ts b/packages/qwik/src/core/shared/error/error.ts index 6816a81efbd..409a03042f4 100644 --- a/packages/qwik/src/core/shared/error/error.ts +++ b/packages/qwik/src/core/shared/error/error.ts @@ -50,7 +50,6 @@ export const codeToText = (code: number, ...parts: any[]): string => { "Element must have 'q:container' attribute.", // 42 'Unknown vnode type {{0}}.', // 43 'Materialize error: missing element: {{0}} {{1}} {{2}}', // 44 - 'SsrError: {{0}}', // 45 'Cannot coerce a Signal, use `.value` instead', // 46 'useComputedSignal$ QRL {{0}} {{1}} returned a Promise', // 47 'ComputedSignal is read-only', // 48 @@ -121,13 +120,12 @@ export const enum QError { elementWithoutContainer = 42, invalidVNodeType = 43, materializeVNodeDataError = 44, - serverHostMismatch = 45, - cannotCoerceSignal = 46, - computedNotSync = 47, - computedReadOnly = 48, - wrappedReadOnly = 49, - promisesNotExpected = 50, - unsafeAttr = 51, + cannotCoerceSignal = 45, + computedNotSync = 46, + computedReadOnly = 47, + wrappedReadOnly = 48, + promisesNotExpected = 49, + unsafeAttr = 50, } export const qError = (code: number, errorMessageArgs: any[] = []): Error => { diff --git a/packages/qwik/src/core/shared/scheduler.ts b/packages/qwik/src/core/shared/scheduler.ts index f5f6777a802..335b1df3e6a 100644 --- a/packages/qwik/src/core/shared/scheduler.ts +++ b/packages/qwik/src/core/shared/scheduler.ts @@ -115,7 +115,6 @@ import { QScopedStyle } from './utils/markers'; import { addComponentStylePrefix } from './utils/scoped-styles'; import { type WrappedSignal, type ComputedSignal, triggerEffects } from '../signal/signal'; import type { TargetType } from '../signal/store'; -import { QError, qError } from './error/error'; // Turn this on to get debug output of what the scheduler is doing. const DEBUG: boolean = false; @@ -294,7 +293,7 @@ export const createScheduler = ( } while (choreQueue.length) { const nextChore = choreQueue.shift()!; - const order = choreComparator(nextChore, runUptoChore, rootVNode, false); + const order = choreComparator(nextChore, runUptoChore, rootVNode); if (order === null) { continue; } @@ -462,28 +461,10 @@ function vNodeAlreadyDeleted(chore: Chore): boolean { * * @param a - The first chore to compare * @param b - The second chore to compare - * @param shouldThrowOnHostMismatch - Controls error behavior for mismatched hosts - * @returns A number indicating the relative order of the chores, or null if invalid. A negative - * number means `a` runs before `b`. + * @returns A number indicating the relative order of the chores. A negative number means `a` runs + * before `b`. */ -function choreComparator( - a: Chore, - b: Chore, - rootVNode: ElementVNode | null, - shouldThrowOnHostMismatch: true -): number; -function choreComparator( - a: Chore, - b: Chore, - rootVNode: ElementVNode | null, - shouldThrowOnHostMismatch: false -): number | null; -function choreComparator( - a: Chore, - b: Chore, - rootVNode: ElementVNode | null, - shouldThrowOnHostMismatch: boolean -): number | null { +function choreComparator(a: Chore, b: Chore, rootVNode: ElementVNode | null): number { const macroTypeDiff = (a.$type$ & ChoreType.MACRO) - (b.$type$ & ChoreType.MACRO); if (macroTypeDiff !== 0) { return macroTypeDiff; @@ -511,11 +492,8 @@ function choreComparator( You are attempting to change a state that has already been streamed to the client. This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR). Problematic Node: ${aHost.toString()}`; - if (shouldThrowOnHostMismatch) { - throw qError(QError.serverHostMismatch, [errorMessage]); - } logWarn(errorMessage); - return null; + return 1; } } @@ -557,7 +535,7 @@ function sortedFindIndex( while (bottom < top) { const middle = bottom + ((top - bottom) >> 1); const midChore = sortedArray[middle]; - const comp = choreComparator(value, midChore, rootVNode, true); + const comp = choreComparator(value, midChore, rootVNode); if (comp < 0) { top = middle; } else if (comp > 0) {