-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hydration): only ignore mutated host attributes (#4385)
- Loading branch information
1 parent
ae5e7be
commit 4d13710
Showing
25 changed files
with
188 additions
and
15 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
4 changes: 4 additions & 0 deletions
4
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-and-class-modify/expected.html
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,4 @@ | ||
<x-cmp aria-label="haha" class="yolo woot" data-foo="bar" data-lwc-host-mutated="aria-label class data-foo"> | ||
<template shadowrootmode="open"> | ||
</template> | ||
</x-cmp> |
3 changes: 3 additions & 0 deletions
3
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-and-class-modify/index.js
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,3 @@ | ||
export const tagName = 'x-cmp'; | ||
export { default } from 'x/cmp'; | ||
export * from 'x/cmp'; |
2 changes: 2 additions & 0 deletions
2
...wc/engine-server/src/__tests__/fixtures/attribute-and-class-modify/modules/x/cmp/cmp.html
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,2 @@ | ||
<template> | ||
</template> |
12 changes: 12 additions & 0 deletions
12
...@lwc/engine-server/src/__tests__/fixtures/attribute-and-class-modify/modules/x/cmp/cmp.js
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,12 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class extends LightningElement { | ||
connectedCallback() { | ||
// Modify this component's class and attributes at runtime | ||
// We expect a data-lwc-host-mutated attr to be added with the mutated attribute names in unique sorted order | ||
this.setAttribute('data-foo', 'bar') | ||
this.classList.add('yolo') | ||
this.classList.add('woot') | ||
this.setAttribute('aria-label', 'haha') | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-aria-modify/expected.html
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<x-cmp aria-activedescendant="foo" aria-busy="true" data-lwc-host-mutated> | ||
<x-cmp aria-activedescendant="foo" aria-busy="true" data-lwc-host-mutated="aria-activedescendant aria-busy"> | ||
<template shadowrootmode="open"> | ||
</template> | ||
</x-cmp> |
4 changes: 4 additions & 0 deletions
4
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-modify-uppercase/expected.html
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,4 @@ | ||
<x-cmp ARIA-LABEL="haha" DATA-FOO="bar" data-lwc-host-mutated="aria-label data-bar data-foo"> | ||
<template shadowrootmode="open"> | ||
</template> | ||
</x-cmp> |
3 changes: 3 additions & 0 deletions
3
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-modify-uppercase/index.js
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,3 @@ | ||
export const tagName = 'x-cmp'; | ||
export { default } from 'x/cmp'; | ||
export * from 'x/cmp'; |
2 changes: 2 additions & 0 deletions
2
...wc/engine-server/src/__tests__/fixtures/attribute-modify-uppercase/modules/x/cmp/cmp.html
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,2 @@ | ||
<template> | ||
</template> |
12 changes: 12 additions & 0 deletions
12
...@lwc/engine-server/src/__tests__/fixtures/attribute-modify-uppercase/modules/x/cmp/cmp.js
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,12 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class extends LightningElement { | ||
connectedCallback() { | ||
// Modify this component's attributes at runtime, using uppercase | ||
// We expect a data-lwc-host-mutated attr to be added with the mutated attribute names in unique sorted order, | ||
// all lowercase | ||
this.setAttribute('DATA-FOO', 'bar') | ||
this.setAttribute('ARIA-LABEL', 'haha') | ||
this.removeAttribute('dAtA-BaR') | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/@lwc/engine-server/src/__tests__/fixtures/getter-class-list/expected.html
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<x-getter-class-list class="a c d-e" data-lwc-host-mutated> | ||
<x-getter-class-list class="a c d-e" data-lwc-host-mutated="class"> | ||
<template shadowrootmode="open"> | ||
</template> | ||
</x-getter-class-list> |
2 changes: 1 addition & 1 deletion
2
packages/@lwc/engine-server/src/__tests__/fixtures/method-remove-attribute/expected.html
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<x-method-remove-attribute data-a data-c data-lwc-host-mutated> | ||
<x-method-remove-attribute data-a data-c data-lwc-host-mutated="data-a data-b data-c data-unknown"> | ||
<template shadowrootmode="open"> | ||
</template> | ||
</x-method-remove-attribute> |
2 changes: 1 addition & 1 deletion
2
packages/@lwc/engine-server/src/__tests__/fixtures/method-set-attribute/expected.html
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<x-method-set-attribute data-boolean="true" data-empty-string data-lwc-host-mutated data-null="null" data-number="1" data-override="override" data-string="test"> | ||
<x-method-set-attribute data-boolean="true" data-empty-string data-lwc-host-mutated="data-boolean data-empty-string data-null data-number data-override data-string" data-null="null" data-number="1" data-override="override" data-string="test"> | ||
<template shadowrootmode="open"> | ||
</template> | ||
</x-method-set-attribute> |
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
35 changes: 35 additions & 0 deletions
35
.../mismatches/host-mutation-in-connected-callback/attr-mutated-class-mismatch/index.spec.js
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,35 @@ | ||
export default { | ||
props: { | ||
ssr: true, | ||
}, | ||
clientProps: { | ||
ssr: false, | ||
}, | ||
snapshot(target) { | ||
const child = target.shadowRoot.querySelector('x-child'); | ||
const div = child.shadowRoot.querySelector('div'); | ||
|
||
return { | ||
child, | ||
div, | ||
}; | ||
}, | ||
test(target, snapshots, consoleCalls) { | ||
const snapshotAfterHydration = this.snapshot(target); | ||
expect(snapshotAfterHydration.child).not.toBe(snapshots.child); | ||
expect(snapshotAfterHydration.div).not.toBe(snapshots.div); | ||
|
||
const { child } = snapshotAfterHydration; | ||
expect(child.getAttribute('data-foo')).toBe('bar'); | ||
expect(child.getAttribute('data-mutatis')).toBe('mutandis'); | ||
expect(child.getAttribute('class')).toBe('is-client'); | ||
|
||
TestUtils.expectConsoleCallsDev(consoleCalls, { | ||
warn: [], | ||
error: [ | ||
'Mismatch hydrating element <x-child>: attribute "class" has different values, expected "is-client" but found "is-server"', | ||
'Hydration completed with errors.', | ||
], | ||
}); | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
...atches/host-mutation-in-connected-callback/attr-mutated-class-mismatch/x/child/child.html
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,3 @@ | ||
<template> | ||
<div>{yolo}</div> | ||
</template> |
9 changes: 9 additions & 0 deletions
9
...smatches/host-mutation-in-connected-callback/attr-mutated-class-mismatch/x/child/child.js
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,9 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
yolo = 'woot'; | ||
|
||
connectedCallback() { | ||
this.setAttribute('data-mutatis', 'mutandis'); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...smatches/host-mutation-in-connected-callback/attr-mutated-class-mismatch/x/main/main.html
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,3 @@ | ||
<template> | ||
<x-child data-foo="bar" class={mismatchingClass}></x-child> | ||
</template> |
9 changes: 9 additions & 0 deletions
9
...mismatches/host-mutation-in-connected-callback/attr-mutated-class-mismatch/x/main/main.js
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,9 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class Main extends LightningElement { | ||
@api ssr; | ||
|
||
get mismatchingClass() { | ||
return this.ssr ? 'is-server' : 'is-client'; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../mismatches/host-mutation-in-connected-callback/class-mutated-attr-mismatch/index.spec.js
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,34 @@ | ||
export default { | ||
props: { | ||
ssr: true, | ||
}, | ||
clientProps: { | ||
ssr: false, | ||
}, | ||
snapshot(target) { | ||
const child = target.shadowRoot.querySelector('x-child'); | ||
const div = child.shadowRoot.querySelector('div'); | ||
|
||
return { | ||
child, | ||
div, | ||
}; | ||
}, | ||
test(target, snapshots, consoleCalls) { | ||
const snapshotAfterHydration = this.snapshot(target); | ||
expect(snapshotAfterHydration.child).not.toBe(snapshots.child); | ||
expect(snapshotAfterHydration.div).not.toBe(snapshots.div); | ||
|
||
const { child } = snapshotAfterHydration; | ||
expect(child.getAttribute('class')).toBe('static mutatis'); | ||
expect(child.getAttribute('data-mismatched-attr')).toBe('is-client'); | ||
|
||
TestUtils.expectConsoleCallsDev(consoleCalls, { | ||
warn: [], | ||
error: [ | ||
'Mismatch hydrating element <x-child>: attribute "data-mismatched-attr" has different values, expected "is-client" but found "is-server"', | ||
'Hydration completed with errors.', | ||
], | ||
}); | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
...atches/host-mutation-in-connected-callback/class-mutated-attr-mismatch/x/child/child.html
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,3 @@ | ||
<template> | ||
<div>{yolo}</div> | ||
</template> |
11 changes: 11 additions & 0 deletions
11
...smatches/host-mutation-in-connected-callback/class-mutated-attr-mismatch/x/child/child.js
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,11 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
yolo = 'woot'; | ||
|
||
connectedCallback() { | ||
this.classList.add('mutatis'); | ||
this.classList.add('mutandis'); | ||
this.classList.remove('mutandis'); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...smatches/host-mutation-in-connected-callback/class-mutated-attr-mismatch/x/main/main.html
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,3 @@ | ||
<template> | ||
<x-child class="static" data-mismatched-attr={mismatchedAttr}></x-child> | ||
</template> |
9 changes: 9 additions & 0 deletions
9
...mismatches/host-mutation-in-connected-callback/class-mutated-attr-mismatch/x/main/main.js
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,9 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class Main extends LightningElement { | ||
@api ssr; | ||
|
||
get mismatchedAttr() { | ||
return this.ssr ? 'is-server' : 'is-client'; | ||
} | ||
} |