-
Notifications
You must be signed in to change notification settings - Fork 53
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
Children of custom element gets rendered twice #32
Comments
nvm. It looks like adding an unnamed |
@donpark Could publish a short example showing your solution with the unnamed slot? |
With HTML emitted using PHP like this: <div class="<?php echo $blockSpec['outerClassName']; ?>">
<talk-section id="talk-block-<?php echo $attributes['blockId']; ?>" display="gutenberg">
<div class="talk-content">
<?php echo $inner_blocks; ?>
</div>
<script type="application/json" class="talk-data">
<?php echo $data; ?>
</script>
</talk-section>
</div> And custom element return [
<link rel="stylesheet" href="/wp-content/plugins/talk/elements/index.css" media="all"></link>,
<div ref={this.sectionRef} className="talk-section" style={sectionStyle}>
<slot />
<TalkAudio
autoLevel={autoLevel}
autoPlay={autoPlay}
recording={recording}
audioRef={this.audioRef}
></TalkAudio>
{chyronComponent}
</div>,
]; Child elements of the custom element get mapped as children of the slot element, allowing the custom element to position them anywhere within its hierarchy. |
@donpark Hi. I'm having the same issue. Can't get it to work somehow with the unnamed slot. Can you alter your codesandbox sample to actually solve the issue? Thank you! |
@mbohgard here is the fixed sample In short,
|
@mbohgard @donpark There is no need to use an unnamed |
@marvinhagemeister Thanks! I had issues with that tho as described here. |
How to achieve same behavior when shadow: false is applied. |
This may be related to #18 but when custom element renders its children property like this:
They are rendered twice in two different styles (shadow and document?) like this:
See: https://codesandbox.io/s/preact-custom-element-rendering-content-issue-g7ko9
I also noticed in some test cases where the custom element, not just children, gets rendered twice when some elements are added. When traced in such cases,
children
property included the root element (direct children ofshadowRoot
) instead of the children from HTML.Looking at
preact-custom-element
source code, I'm having difficulty finding wherechildren
parameter comes from. In my 'bare-metal' custom element implementation, I capturechildren
via aMutationObserver
like this:The text was updated successfully, but these errors were encountered: