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

teleportTo does not work with HTML Element. #33

Closed
luxterful opened this issue Dec 2, 2023 · 3 comments · Fixed by #34
Closed

teleportTo does not work with HTML Element. #33

luxterful opened this issue Dec 2, 2023 · 3 comments · Fixed by #34
Assignees
Labels
bug Something isn't working

Comments

@luxterful
Copy link

When is pass an HTML Element to the teleportTo property in the config, it does not work.

I have analysed the code a bit and I guess the problem is the mergeDeep function. There is no check in it if the passed Element is an HTML Element, and therefore it is interpreted as an Object which will then be "ripped apart".

A quick fix would be to add a condition like && source[key].nodeType !== 1 in the mergeDeep function like:

export function mergeDeep<T>(target: T, source: Record<string, any>): T {
   const merged: T = { ...target }

   for (const key in source) {
      if (source.hasOwnProperty(key)) {
         if (source[key] && typeof source[key] === 'object' && source[key].nodeType !== 1) {
            merged[key as keyof T] = mergeDeep(target[key as keyof T], source[key]) as T[keyof T]
         } else {
            merged[key as keyof T] = source[key]
         }
      }
   }

   return merged
}
@luxterful
Copy link
Author

The added condition does the same as the lodash isElemenet function.

@smastrom smastrom self-assigned this Dec 2, 2023
@smastrom smastrom added the bug Something isn't working label Dec 2, 2023
@smastrom
Copy link
Owner

smastrom commented Dec 2, 2023

Thank you for reporting, this is indeed a bug. I will release a fix in the next version.

@luxterful
Copy link
Author

@smastrom all right! Thank you very much!

@smastrom smastrom linked a pull request Dec 9, 2023 that will close this issue
smastrom added a commit that referenced this issue Dec 9, 2023
* Core - Fix teleport to custom HTMLElement (#33)

* Core - Up deps, bump 1.4.5

* Pkg - Edit README and LICENSE

* Pkg - Edit workflows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants