Skip to content

Commit

Permalink
feat: log a warning instead of throwing an error for server host mism…
Browse files Browse the repository at this point in the history
…atch error
  • Loading branch information
Varixo committed Jan 10, 2025
1 parent f3404ff commit 1ef14ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-poems-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik.dev/core': patch
---

feat: log a warning instead of throwing an error for server host mismatch error
14 changes: 6 additions & 8 deletions packages/qwik/src/core/shared/error/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand Down
34 changes: 6 additions & 28 deletions packages/qwik/src/core/shared/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1ef14ba

Please sign in to comment.