Skip to content

fix: diff WC respecting internal DOM modifications #18

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

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

aralroca
Copy link
Collaborator

@aralroca aralroca commented Nov 9, 2024

Fixes brisa-build/brisa#611

The problem that happened is that when doing diffing of the WC made 2 steps, first, it made an insert (L176), and after adding the node, it entered in line 188 and made a diffing with the newNode when the insertedNode was already a clone of the new one, but of course, the new one did not have the internal change of the DOM modified by the WC (this.setAttribute), then it is as if it had not been applied.

https://github.com/aralroca/diff-dom-streaming/blob/0169dc1c9315099f340f7d60599e9fecf201eaca/src/index.ts#L173-L188

Example of WC:

class TestWC extends HTMLElement {
  connectedCallback() {
    this.setAttribute("data-connected", "true");
  }
}
customElements.define("test-wc", TestWC);

This PR fix the removal of data-connected in this extra unnecessary step.

Removing this code, all the tests continue passing and it solves the new tests that I have added.

CC: @AlbertSabate

@aralroca aralroca requested a review from danielart November 9, 2024 19:16
@aralroca aralroca merged commit 6f484b0 into main Nov 9, 2024
1 check passed
@aralroca aralroca deleted the aralroca/fix-wc-diffing branch November 9, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onMount called before the WC is on the DOM (during SPA navigation)
1 participant