hhvm / xhp-lib

Class libraries for XHP. XHP is a Hack feature that augments the syntax of the language such that XML document fragments become valid Hack expressions.
http://facebook.github.io/xhp-lib/
MIT License
1.38k stars 160 forks source link

Remove/deprecate/move XHPHelpers transferAttributes behavior #230

Closed fredemmott closed 4 years ago

fredemmott commented 4 years ago

Originally expected to remove this from v3.x due to the introduction of XHP attribute splat - announced with https://github.com/hhvm/xhp-lib/releases/tag/v2.6.0

This has some behavior behavior, e.g:

$x = <foo data-bar="baz" />
$s1 = $x->toString();
$s2 = $x->toString();
assert($s1 === $s2); // fails as transferAttributes calls removeAttribute

Additionally, this is causing problems with #135 - after render has started, setAttribute, forceAttribute, removeAttribute etc must error.

fredemmott commented 4 years ago

Also probably worth special-casing the id attribute the same way transferAttributesToRenderedRoot does - if both set and !=, it's probably a bug

fredemmott commented 4 years ago

This might end up being "deprecate for new code" instead of remove - e.g.

  1. if every return statement in a render function of the form return <foo>...</foo>, replace with return <foo {...$this}>...</foo>
  2. otherwise, add use IXHPWithImplicitCopy_DEPRECATED or similar
  3. encourage manual migration to spread operator for things that use that trait, but this might be a slow process