-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: log a warning instead of throwing an error for server host mismatch error #7236
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You can't just delete a line here, each error must be on a single line so that error links work.
If you renumber all errors it's ok but once it's stable you shouldn't renumber any more. What you can do is use old numbers for new errors I suppose.
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.
yeah I know, it is alpha thats why I removed the error