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

bug: Slot-Fallback hidden when newlines exists #6129

Open
3 tasks done
dutscher opened this issue Jan 29, 2025 · 7 comments
Open
3 tasks done

bug: Slot-Fallback hidden when newlines exists #6129

dutscher opened this issue Jan 29, 2025 · 7 comments
Labels
Request For Comments Seeking commentary on an issue or PR from the community

Comments

@dutscher
Copy link

Prerequisites

Stencil Version

4.23+

Current Behavior

Hi there,
i encounter a bug with the latest version 4.25.1, but the issue comes from 4.23.1 #6082. And the correct addition see here the the comment https://github.com/johnjenkins/stencil/blob/2c607c6407f9ed2a256ec85973e1c6384b701d21/src/runtime/slot-polyfill-utils.ts#L10

The problem is:

Image

<s-text-field>
	<span slot="label">Label</span>
</s-text-field>

Due whitespace/newlines in the default slot is the which gets and its hidden.


Here is everything fine:

Image

<s-text-field><span slot="label">Label</span></s-text-field>

Here we have an empty which get and its not hidden.

Expected Behavior

is visible with empty default slot with newlines and whitespaces.

System Info

Platform: windows (10.0.22621)
   CPU Model: AMD Ryzen 7 7840U w/ Radeon  780M Graphics      (16 cpus)
    Compiler: C:\www\repos\huk\web-lib-style\node_modules\@stencil\core\compiler\stencil.js
       Build: 1737767058
     Stencil: 4.25.1
  TypeScript: 5.5.4
      Rollup: 2.56.3
      Parse5: 7.1.2
      jQuery: 4.0.0-pre
      Terser: 5.31.1

Steps to Reproduce

The render method ot this stencil component looks like this:

@Component({
  tag: 's-text-field',
})
export class STextField {
render() {
 return (
      <Host>
        <label class={'wrapper'}>
          <div class={'description'}>
            <div>
              <slot name="label" />
            </div>
          </div>
          <div class={'input-wrapper'}>
            <div class={'input'}>
              <slot>
                <input />
              </slot> 
            </div>
          </div>
    </label>
 </Host>);
}
}

Code Reproduction URL

https://codesandbox.io/p/devbox/slot-bug-reproduce-6hhnwj

Additional Information

The slot fallback ist needed to get a external <input into the webcomponent:

<s-text-field>
	<input type="text" />
</s-text-field>

Cheers and thanks for your hard work!

@ionitron-bot ionitron-bot bot added the triage label Jan 29, 2025
@johnjenkins
Copy link
Contributor

hey! Thanks for raising the issue.

I don't think this is a stencil issue per se', rather just how custom elements / slots are implemented by default.

I downgraded your project to stencil 3 and the 'problem' remains

What would happen if you wanted to slot an empty space? (e.g. you slot whatever a user types into an input)

Some references:

Lit's docs
Image

Discussion with browser implementers

Ongoing discussion around DSD

@dutscher
Copy link
Author

But it works with stencil "@stencil/core": "^4.22.3".
And sorry its important to not use the shadowDom, i correct the codesandbox.

Image

Also with 4.23.0

Image

But with 4.23.1

Image

Cheers

@johnjenkins
Copy link
Contributor

johnjenkins commented Jan 29, 2025

Ah ok, thank you - that makes it clearer!

But it does mean we have to have a different conversation :D ... Stencil's proprietary slot code now correctly follows / mimics it's native counterpart.

I'll leave it to @christian-bromann to think about whether Stencil should break from convention or not.

@christian-bromann
Copy link
Member

IMHO we should strictly follow web standards here and don't break from any conventions as this will be hard to document and maintain over time.

@dutscher do you see a way how we can enhance Stencil with a feature instead to simplify the use case you are working with? Maybe custom Stencil properties to the <slot /> tag that modifies this behavior?

@christian-bromann christian-bromann added Request For Comments Seeking commentary on an issue or PR from the community and removed triage labels Feb 3, 2025
@johnjenkins
Copy link
Contributor

it's tricky 'cos there's not even a potential spec to think about or work from.
Closest we get is a suggestion of <slot trimwhitespace>Fallback</slot>

@christian-bromann
Copy link
Member

That's what I had in mind as well. Alternatively we could introduce a Stencil option that allows to defines specific behavior flags for specific components. This would keep the feature more within Stencils API realm rather than extending one we don't control (e.g. what if the webcomponent spec introduces the same attribute with a different meaning, it also could get user confused as they don't immediately connect this flag to be Stencil specific).

@dutscher
Copy link
Author

dutscher commented Feb 4, 2025

the trimwhitespace (or trim only) attribute is awesome.
this will fix the other issue that the css [name=paste]:empty {display:none} selector works on <slot name="paste" trim></slot> <comp><div slot="paste"> </div></comp>

cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Request For Comments Seeking commentary on an issue or PR from the community
Projects
None yet
Development

No branches or pull requests

3 participants