galvez / unihead

Fast and minimal JS <head> server-side writer and client-side manager.
26 stars 3 forks source link

The node to be replaced is not a child of this node #4

Open zanmato opened 2 months ago

zanmato commented 2 months ago

I'm getting this error now and then. I've not been able to make a minimal reproduction of the issue, but I think it's related to updating the head server side and client side (some clientOnly pages).

It could be resolved with replacing replaceChild with searching for the given element like (in setSingle), but I'm not sure if this has any drawbacks.

this.document.head.querySelector(elem).replaceWith(this.route[elem].create({ value, attrs }))
Uncaught (in promise) NotFoundError: Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.
    at _HeadManager.setSingle (client.mjs:168:28)
    at _HeadManager.update (client.mjs:134:16)
    at Proxy.<anonymous> (client.mjs:226:38)
    at beforeCreate (client.js:51:12)
galvez commented 2 months ago

I'm investigating this now.

galvez commented 2 months ago

I'm considering deprecating this package in favor of unhead — looking at the logs, I can see Harlan is incredibly dedicated to it, and it now has tested integrations for Vue, React, Svelte, Solid.js and Angular — which tells me it's framework agnostic enough for what we want to accomplish in @fastify/vite.

Nevertheless, I'll try and figure out what's happening here, so we can have a patch release.

zanmato commented 2 months ago

I can see if I can refactor it to use unhead tomorrow

zanmato commented 1 month ago

It may also be related to <link rel="alternate" hreflang="xx"-tags, I realized that it can't diff these tags so they just keep being added to the head