-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7236 from QwikDev/v2-warn-server-mismatch-error
feat: log a warning instead of throwing an error for server host mismatch error
- Loading branch information
Showing
7 changed files
with
193 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/qwik/src/core/shared/scheduler-document-position.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
import { | ||
vnode_getFirstChild, | ||
vnode_getNextSibling, | ||
vnode_newUnMaterializedElement, | ||
} from '../client/vnode'; | ||
import type { ContainerElement, ElementVNode, QDocument } from '../client/types'; | ||
import { vnode_documentPosition } from './scheduler-document-position'; | ||
import { createDocument } from '@qwik.dev/dom'; | ||
|
||
describe('vnode_documentPosition', () => { | ||
let parent: ContainerElement; | ||
let document: QDocument; | ||
let vParent: ElementVNode; | ||
beforeEach(() => { | ||
document = createDocument() as QDocument; | ||
document.qVNodeData = new WeakMap(); | ||
parent = document.createElement('test') as ContainerElement; | ||
parent.qVNodeRefs = new Map(); | ||
vParent = vnode_newUnMaterializedElement(parent); | ||
}); | ||
afterEach(() => { | ||
parent = null!; | ||
document = null!; | ||
vParent = null!; | ||
}); | ||
|
||
it('should compare two elements', () => { | ||
parent.innerHTML = '<b></b><i></i>'; | ||
const b = vnode_getFirstChild(vParent) as ElementVNode; | ||
const i = vnode_getNextSibling(b) as ElementVNode; | ||
expect(vnode_documentPosition(b, i, null)).toBe(-1); | ||
expect(vnode_documentPosition(i, b, null)).toBe(1); | ||
}); | ||
it('should compare two virtual vNodes', () => { | ||
parent.innerHTML = 'AB'; | ||
document.qVNodeData.set(parent, '{B}{B}'); | ||
const a = vnode_getFirstChild(vParent) as ElementVNode; | ||
const b = vnode_getNextSibling(a) as ElementVNode; | ||
expect(vnode_documentPosition(a, b, null)).toBe(-1); | ||
expect(vnode_documentPosition(b, a, null)).toBe(1); | ||
}); | ||
it('should compare two virtual vNodes', () => { | ||
parent.innerHTML = 'AB'; | ||
document.qVNodeData.set(parent, '{{B}}{B}'); | ||
const a = vnode_getFirstChild(vParent) as ElementVNode; | ||
const a2 = vnode_getFirstChild(a) as ElementVNode; | ||
const b = vnode_getNextSibling(a) as ElementVNode; | ||
expect(vnode_documentPosition(a2, b, null)).toBe(-1); | ||
expect(vnode_documentPosition(b, a2, null)).toBe(1); | ||
}); | ||
}); |
118 changes: 118 additions & 0 deletions
118
packages/qwik/src/core/shared/scheduler-document-position.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { VNodeProps, type ElementVNode, type VNode } from '../client/types'; | ||
import { | ||
vnode_getNextSibling, | ||
vnode_getPreviousSibling, | ||
vnode_getProp, | ||
vnode_locate, | ||
} from '../client/vnode'; | ||
import type { ISsrNode } from '../ssr/ssr-types'; | ||
import { QSlotParent } from './utils/markers'; | ||
|
||
/// These global variables are used to avoid creating new arrays for each call to `vnode_documentPosition`. | ||
const aVNodePath: VNode[] = []; | ||
const bVNodePath: VNode[] = []; | ||
/** | ||
* Compare two VNodes and determine their document position relative to each other. | ||
* | ||
* @param a VNode to compare | ||
* @param b VNode to compare | ||
* @param rootVNode - Root VNode of a container | ||
* @returns -1 if `a` is before `b`, 0 if `a` is the same as `b`, 1 if `a` is after `b`. | ||
*/ | ||
export const vnode_documentPosition = ( | ||
a: VNode, | ||
b: VNode, | ||
rootVNode: ElementVNode | null | ||
): -1 | 0 | 1 => { | ||
if (a === b) { | ||
return 0; | ||
} | ||
|
||
let aDepth = -1; | ||
let bDepth = -1; | ||
while (a) { | ||
const vNode = (aVNodePath[++aDepth] = a); | ||
a = (vNode[VNodeProps.parent] || | ||
(rootVNode && vnode_getProp(a, QSlotParent, (id) => vnode_locate(rootVNode, id))))!; | ||
} | ||
while (b) { | ||
const vNode = (bVNodePath[++bDepth] = b); | ||
b = (vNode[VNodeProps.parent] || | ||
(rootVNode && vnode_getProp(b, QSlotParent, (id) => vnode_locate(rootVNode, id))))!; | ||
} | ||
|
||
while (aDepth >= 0 && bDepth >= 0) { | ||
a = aVNodePath[aDepth] as VNode; | ||
b = bVNodePath[bDepth] as VNode; | ||
if (a === b) { | ||
// if the nodes are the same, we need to check the next level. | ||
aDepth--; | ||
bDepth--; | ||
} else { | ||
// We found a difference so we need to scan nodes at this level. | ||
let cursor: VNode | null = b; | ||
do { | ||
cursor = vnode_getNextSibling(cursor); | ||
if (cursor === a) { | ||
return 1; | ||
} | ||
} while (cursor); | ||
cursor = b; | ||
do { | ||
cursor = vnode_getPreviousSibling(cursor); | ||
if (cursor === a) { | ||
return -1; | ||
} | ||
} while (cursor); | ||
if (rootVNode && vnode_getProp(b, QSlotParent, (id) => vnode_locate(rootVNode, id))) { | ||
// The "b" node is a projection, so we need to set it after "a" node, | ||
// because the "a" node could be a context provider. | ||
return -1; | ||
} | ||
// The node is not in the list of siblings, that means it must be disconnected. | ||
return 1; | ||
} | ||
} | ||
return aDepth < bDepth ? -1 : 1; | ||
}; | ||
|
||
/// These global variables are used to avoid creating new arrays for each call to `ssrNodeDocumentPosition`. | ||
const aSsrNodePath: ISsrNode[] = []; | ||
const bSsrNodePath: ISsrNode[] = []; | ||
/** | ||
* Compare two SSR nodes and determine their document position relative to each other. Compares only | ||
* position between parent and child. | ||
* | ||
* @param a SSR node to compare | ||
* @param b SSR node to compare | ||
* @returns -1 if `a` is before `b`, 0 if `a` is the same as `b`, 1 if `a` is after `b`. | ||
*/ | ||
export const ssrNodeDocumentPosition = (a: ISsrNode, b: ISsrNode): -1 | 0 | 1 => { | ||
if (a === b) { | ||
return 0; | ||
} | ||
|
||
let aDepth = -1; | ||
let bDepth = -1; | ||
while (a) { | ||
const ssrNode = (aSsrNodePath[++aDepth] = a); | ||
a = ssrNode.currentComponentNode!; | ||
} | ||
while (b) { | ||
const ssrNode = (bSsrNodePath[++bDepth] = b); | ||
b = ssrNode.currentComponentNode!; | ||
} | ||
|
||
while (aDepth >= 0 && bDepth >= 0) { | ||
a = aSsrNodePath[aDepth] as ISsrNode; | ||
b = bSsrNodePath[bDepth] as ISsrNode; | ||
if (a === b) { | ||
// if the nodes are the same, we need to check the next level. | ||
aDepth--; | ||
bDepth--; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
return aDepth < bDepth ? -1 : 1; | ||
}; |
Oops, something went wrong.