million icon indicating copy to clipboard operation
million copied to clipboard

bug: Uncaught DOMException: Failed to execute 'replaceChild' on 'Node'

Open jalexanderII opened this issue 1 year ago • 12 comments

Uncaught TypeError: Cannot read properties of undefined (reading '__t')
    at Block.p (million.52d69b41.mjs:779:1)
    at ArrayBlock.p (million.52d69b41.mjs:516:1)
    at react.mjs:84:1

and

Uncaught DOMException: Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.
    at Block.p (http://localhost:3000/static/js/bundle.js:1078098:29)
    at ArrayBlock.p (http://localhost:3000/static/js/bundle.js:1077859:16)
    at http://localhost:3000/static/js/bundle.js:1077131:67

Unable to understand why the error is occurring, this should be the problem code:

          if (newValue && typeof newValue === "object" && "foreign" in newValue) {
            const scopeEl = el[TEXT_NODE_CACHE][k];
            if ("unstable" in newValue && oldValue !== newValue) {
              const newScopeEl = newValue.current;
              el[TEXT_NODE_CACHE][k] = newScopeEl;
              replaceChild$.call(el, newScopeEl, scopeEl);
            } else {
              newValue.current = scopeEl;
            }
            continue;

inside of class Block.

I tried to // million-ignore all of the functions in the components where the error occurred but the error didn't go away.

Potential solution, Conditional Replacement: Check if oldChild is actually a child of parentNode before using replaceChild. You can verify with parentNode.contains(oldChild)

if (parentNode.contains(oldChild)) {
  parentNode.replaceChild(newChild, oldChild);
} else {
  // Handle the case when oldChild is not a child of parentNode
}

jalexanderII avatar Dec 21 '23 20:12 jalexanderII

Thanks for opening this issue! A maintainer will review it soon.

github-actions[bot] avatar Dec 21 '23 20:12 github-actions[bot]

Hi can you provide a repro!

aidenybai avatar Dec 22 '23 07:12 aidenybai

@jalexanderII, are you there?

tobySolutions avatar Dec 24 '23 10:12 tobySolutions

Hey team. I do not know how to reproduce. I am not sure why this is occurring or what in my code is triggering the problem. All I know is the source of the error from the error message.

jalexanderII avatar Dec 24 '23 16:12 jalexanderII

@tobySolutions & @aidenybai

jalexanderII avatar Dec 26 '23 21:12 jalexanderII

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.

github-actions[bot] avatar Jan 11 '24 00:01 github-actions[bot]

I am facing the same issue for my site. Here is the error in console - image

This is my vite.config.js image

This is main App.js file image

I'm not sure from where the error is coming from though. Any help would be highly appreciated.

riju-stone avatar Jan 11 '24 04:01 riju-stone

I'm also facing the same issue. I'm rendering same component 4 times, but it's only showing 1 time.

image

sample code url: https://stackblitz.com/edit/vitejs-vite-ofx7tf?file=src%2FApp.tsx

vimalsonara avatar Jan 20 '24 13:01 vimalsonara

I'm also facing the same issue. I'm rendering same component 4 times, but it's only showing 1 time.

image

sample code url: https://stackblitz.com/edit/vitejs-vite-ofx7tf?file=src%2FApp.tsx

Thanks for the reproduction. I'll definitely check it and get back to you!

tobySolutions avatar Jan 20 '24 14:01 tobySolutions

I'm also facing the same issue. I'm rendering same component 4 times, but it's only showing 1 time. image sample code url: https://stackblitz.com/edit/vitejs-vite-ofx7tf?file=src%2FApp.tsx

Thanks for the reproduction. I'll definitely check it and get back to you!

Hey there @vimalsonara, so I made tweaks and I used manual mode to make the optimizations for MonthDaysDisplay, I had to ignore automatic mode for the MonthDaysDisplay component: https://stackblitz.com/edit/vitejs-vite-hjcfai?file=src%2FMonthDaysDisplay.tsx

tobySolutions avatar Jan 20 '24 14:01 tobySolutions

I'm also facing the same issue. I'm rendering same component 4 times, but it's only showing 1 time. image sample code url: https://stackblitz.com/edit/vitejs-vite-ofx7tf?file=src%2FApp.tsx

Thanks for the reproduction. I'll definitely check it and get back to you!

Hey there @vimalsonara, so I made tweaks and I used manual mode to make the optimizations for MonthDaysDisplay, I had to ignore automatic mode for the MonthDaysDisplay component: https://stackblitz.com/edit/vitejs-vite-hjcfai?file=src%2FMonthDaysDisplay.tsx

Thank you @tobySolutions It's working now.

vimalsonara avatar Jan 20 '24 16:01 vimalsonara

I'm also facing the same issue. I'm rendering same component 4 times, but it's only showing 1 time. image sample code url: https://stackblitz.com/edit/vitejs-vite-ofx7tf?file=src%2FApp.tsx

Thanks for the reproduction. I'll definitely check it and get back to you!

Hey there @vimalsonara, so I made tweaks and I used manual mode to make the optimizations for MonthDaysDisplay, I had to ignore automatic mode for the MonthDaysDisplay component: https://stackblitz.com/edit/vitejs-vite-hjcfai?file=src%2FMonthDaysDisplay.tsx

Thank you @tobySolutions It's working now.

My pleasure @vimalsonara!

tobySolutions avatar Jan 20 '24 20:01 tobySolutions

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.

github-actions[bot] avatar Feb 05 '24 00:02 github-actions[bot]