Patch prepends result to parent.
See original GitHub issueBy default the patch method prepends the result to the parent element. This means that if you have a page rendered on the server with some default content and then use path on the parent element, Pidocom prepends using element.insertBefore
. Case in view, say you have a header with title, menu, etc. rendered on the server and then try to use patch to inject content into the document body at load time. Picodom prepends that content before the header, pushing it down. The only way to avoid this as it stands is to always use empty containers with patch. This seams very wasteful. It would be nice if the insertion behavior followed norms that developers expect so they aren’t scratching their heads when things are prepended.
Otherwise, hey Jorge, good job on this project.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
This might be mitigated also by the change proposed here in #89 - for the top-most call to
patch
, order would not be an issue or a concern at all, since the caller would be responsible for designating exactly the element they want to patch; it’s order wouldn’t be affected at all.@rbiggs In the new API:
The patch function now returns an element, if none is given, allowing you to append it to a container if that’s what you want. If you pass an existing element instead, patchdom will patch that element (attempting to recycle any existing markup), instead of using it as a container like in the past.