preact-markup icon indicating copy to clipboard operation
preact-markup copied to clipboard

Markup component will not update if the mapping of custom elements change

Open d3x7r0 opened this issue 6 years ago • 2 comments

When using the option to add a map of custom elements the component will not update if said mapping changes.

I think the problem might be here: https://github.com/developit/preact-markup/blob/034c4c6e13029d94db57c8a565191a03b214eb83/src/index.js#L11-L14

Now I don't know if this is intended behaviour or just a oversight.

d3x7r0 avatar May 24 '19 09:05 d3x7r0

@d3x7r0 it's an oversight, but I think if we want to add support for updating when the listing changes we'll need to deeply compare the object values within props.components:

- shouldComponentUpdate({ wrap, type, markup }) { 
+ shouldComponentUpdate({ wrap, type, markup, components }) { 
	let p = this.props; 
+	if (Object.keys(components).join()!=Object.keys(p.components).join()) return true;
+	for (let i in Object(components)) if (components[i]!==p.components[i]) return true;
	return wrap!==p.wrap || type!==p.type || markup!==p.markup; 
 }

developit avatar Jul 10 '19 11:07 developit

That looks like it might be a good enough solution yes. I'm also going to steal that key comparison for my toolset. I never thought of doing it that way but it's such a great idea I'm going to keep it handy :)

d3x7r0 avatar Jul 10 '19 11:07 d3x7r0