-
Notifications
You must be signed in to change notification settings - Fork 7
Sub-component support #35
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
Conversation
if ( str_starts_with( $error->message, 'Tag template invalid' ) ) { | ||
$msg = $error->message; | ||
if ( str_starts_with( $msg, 'Tag ' ) && str_ends_with( $msg, " invalid\n" ) ) { | ||
// discard "Tag xyz invalid" messages from libxml2 < 2.14.0(?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it’s annoying that it doesn’t happen for me locally, only in CI :S
This looks good to me. It's unfortunate that we need the error workaround for libxml, but that seems like it might be unavoidable. |
The App class lets us reuse the same HtmlParser and JsExpressionParser across multiple components (note that JsExpressionParser returns an unevaluated expression, so it’s fine to cache its results even if they’re going to be evaluated with different data later), and also keeps a library of components. The components are loaded and compiled on-demand the first time they’re used, and reused afterwards; for this, Component now clones its root node before operating on it. For Component to work correctly, it’s important that the cloned node still has a parent node (otherwise it’s considered to have been removed from the DOM, and most of the processing for it is skipped); use a cloneOwner node for that purpose. (For now, it’s just the document’s document element, i.e. the <html>, but we could make it a separate node later if we prefer. It just has to be outside the root node.) (If you’re wondering, my motivation for making the components input either string or callable is that it probably makes sense not to load all the component files into strings upfront, but to only do that if the component is needed.)
This is a bit odd in that Component doesn’t even know which components are registered in the app; sub-component handling is triggered iff the tag name contains a hyphen. I think this is reasonable, but we might still end up changing it. Note that the sub-component must be a descendent of the template root note; a template cannot just consist of a call to a sub-component. (If it does, Component::render() crashes when trying to remove the $rootNode from the cloneOwner because it’s already been replaced in handleComponent().)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great - let's give it a go!
See the individual commit messages. Support for callable components is not included, since that needs more work (see the
app+callable
branch).