Skip to content
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

Slot CRUD does not work properly when shadow is false #2877

Closed
chenyulun opened this issue Apr 8, 2021 · 1 comment · Fixed by #5135
Closed

Slot CRUD does not work properly when shadow is false #2877

chenyulun opened this issue Apr 8, 2021 · 1 comment · Fixed by #5135
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. slot-related

Comments

@chenyulun
Copy link

Stencil version:

 @stencil/core@2.5.2

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

Slot increase delete add update when shadow is false does not work properly

  1. When there is no slot inside Web Components, the user passes the slot to be present, but if shadow
    Is not displayed when true
@Component({
  tag: 'pui-example',
  shadow: false,
})
export class Example implements ComponentInterface {
render() {return (<Host></Host>)}
}

The wrong presentation flattened DOM:

<pui-example class="hydrated"><!----><div><span>outside default slot</span></div></pui-example>

Expected behavior flattened DOM

<pui-example class="hydrated"><!----><div hidden=""><span>outside default slot</span></div></pui-example>
  1. Initialize the hidden slot, pass it to the slot node when used, and display the slot inside the component with parameters that can correctly process the slot to its actual location. However, if the internal slot of the component is hidden here, the external slot node disappears and the external slot node should be moved back to its original position for hiding

  2. When you outsource an incoming slot and receive it internally, delete the outsourced slot. The hidden property of the internal slot-fb is not removed

When shadow is true, the browser will handle it just fine

Expected behavior:

Slot increase, delete and update when shadow is false will work normally

Steps to reproduce:

Related code:

import { Component, ComponentInterface, Prop, Host } from '@stencil/core';
@Component({
  tag: 'pui-example',
  shadow: false,
})
export class Example implements ComponentInterface {
  /**
   * Whether or not to show slot
  */
  @Prop() enabled = false;
  render(): VNode {
    return (
      <Host>
        {this.enabled && (
          <div data-txt="slot wrapper">
            <slot>
              <span>fallback default slot</span>
            </slot>
          </div>
        )}
      </Host>
    );
  }
}

DOM nodes to use and display:

// Use the code(Vue) showSlot = true
<pui-example>
  <div v-if="showSlot" data-txt="outside default slot">
    <span>outside default slot</span>
  </div>
</pui-example>
// flattened DOM: ====》Incoming slot should be hidden
<pui-example class="hydrated">
  <!---->
  <div data-txt="outside default slot">
    <span>outside default slot</span>
  </div>
</pui-example>

When the following statement is executed:

document.getElementsByTagName('pui-example')[0].enabled = true

This is normal as shown below

<pui-example class="hydrated"><!----><div data-txt="slot wrapper"><slot-fb hidden=""><span>fallback default slot</span></slot-fb><div data-txt="outside default slot"><span>outside default slot</span></div></div></pui-example>

When the following statement is executed:

document.getElementsByTagName('pui-example')[0].enabled = false

Incoming slot nodes are deleted: ====》It should be moved back to its original position and then hidden

<pui-example class="hydrated"><!----></pui-example>

Other information:

@ionitron-bot ionitron-bot bot added the triage label Apr 8, 2021
@ionitron-bot ionitron-bot bot removed the triage label Nov 13, 2021
@rwaskiewicz rwaskiewicz added Bug: Needs Validation Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team and removed Feature: Renderer labels Mar 25, 2022
@rwaskiewicz rwaskiewicz added slot-related Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. and removed Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team labels Sep 6, 2023
tanner-reits added a commit that referenced this issue Dec 6, 2023
Hides any content that is projected through to a Stencil component that does not have a destination slot. Only for `scoped` components.

Fixes #2877

STENCIL-938
github-merge-queue bot pushed a commit that referenced this issue Dec 6, 2023
…onents (#5135)

* fix(runtime): re-relocate slot if parent element's tagname changes

If a slot is located in an element and that element's tag is dynamically changed (e.g. from `p` to `span`), we need to re-relocate the slot on re-render

STENCIL-672: slot element loses its parent reference and disappears when its parent is rendered conditionally

Fixes: #4284, #3913

* add e2e tests

* code documentation

* put changes behind slot fix flag

* resolve new SNC

* reset `hidden` state of nodes on relocate

It is possible for slotted content to still be invisible in the DOM if the slot was not rendered on the first render. This commit resets the `hidden` attribute of a node on successful relocation.

STENCIL-1053

* hide slot content without a home in `scoped` components

Hides any content that is projected through to a Stencil component that does not have a destination slot. Only for `scoped` components.

Fixes #2877

STENCIL-938

* add e2e tests for hiding content without a slot

* revert karma config

* PR feedback

Co-authored-by: Christian Bromann <git@bromann.dev>

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
@christian-bromann
Copy link
Member

A fix for this issue was released in v4.8.2. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. slot-related
Projects
None yet
4 participants