Skip to content
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

fix(runtime): append newChild if parent node doesn't match with patched node #6141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

itsjustaplant
Copy link

@itsjustaplant itsjustaplant commented Feb 4, 2025

What is the current behavior?

GitHub Issue Number: #6140

What is the new behavior?

If patched node (this) is not the same node of currentChild, it uses appendChild to insert the newChild to patched node

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

Other information

@itsjustaplant itsjustaplant requested a review from a team as a code owner February 4, 2025 11:18
@christian-bromann
Copy link
Member

christian-bromann commented Feb 4, 2025

@itsjustaplant thanks for raising the PR, mind creating a test to ensure we don't regress on this? I recommend to create a WebdriverIO test as it provides the most flexibility creating the test. Let me know if you have any questions.

@itsjustaplant itsjustaplant force-pushed the fix/runtime_patchInsertBefore_node_not_found_error branch from cba9889 to 19db966 Compare February 5, 2025 13:13
@itsjustaplant itsjustaplant changed the title fix(runtime): use unpatched parentNode as a fallback while inserting … fix(runtime): append newChild if parent node doesn't match with patched node Feb 5, 2025
@itsjustaplant
Copy link
Author

Hi @christian-bromann , I am unable to reproduce this issue in either a plain Stencil app or WebdriverIO tests. I believe that this only happens in React apps. PS: I replaced the unpatched insertBefore with appendChild as a fallback method as i believe that appendChild is safer.

@christian-bromann
Copy link
Member

@itsjustaplant mhm 🤔 it would be good if we could validate this fix somehow, otherwise it may become difficult at some point to understand why we've put this in place or whether it still is relevant to Stencil.

@itsjustaplant
Copy link
Author

itsjustaplant commented Feb 10, 2025

Hi @christian-bromann , I have a reproduction repository here. If you run the my-app, you will see the error in couple of seconds due to mocked fetch. As it only happens in react, i don't know what more could i add as reproduction but this commit somehow introduced the bug on stencil side (it was previously on react-dom).

const parentNode = (currentChild as d.PatchedSlotNode)?.__parentNode;
if (parentNode && !this.isSameNode(parentNode)) {
    return this.appendChild(newChild);
}

You can consider this as a fallback that is triggered when parentNodes doesn't match.
If parentNodes are not same we simply call appendChild as it will handle the placement of the slotted node.
And if parentNodes match, the original return (this as d.RenderNode).__insertBefore(newChild, currentChild); will be called.

@yigityuce
Copy link
Contributor

yigityuce commented Feb 12, 2025

@itsjustaplant mhm 🤔 it would be good if we could validate this fix somehow, otherwise it may become difficult at some point to understand why we've put this in place or whether it still is relevant to Stencil.

hi @christian-bromann hope you are well since from last touchpoint between us. Alperen (@itsjustaplant) is one of our team members and as he said unfortunately we are having this issue only in react. Probably react does bulk update on DOM after stencil does update on the DOM, and, while react was trying to use insertBefore, the parentNode is not in the previous place where react stores in its vdom. (my strong guess is react does these kind of bulk operations in nextTick, and in the nextTick the actual DOM is already changed by Stencil)

So, unfortunately WDIO test is not able to be providable. However, I understand your concern and agree with you. Maybe we can put some more detail to the comment section in the code that describes the issue better. Would it work for you?

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.

3 participants