-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat(core): slot controller ssr hint attributes #2893
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 9f5ecaa The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Commitlint tests passed!More Info{
"valid": true,
"errors": [],
"warnings": [],
"input": "feat(core): slot controller ssr hint attributes"
} |
✅ Deploy Preview for patternfly-elements ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for patternfly-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
It's such a bummer that Lit-SSR doesn't support reading children. I get it but it's unfortunate. I think it would be a great feature if you could disable "streaming mode" on Lit-SSR and you'd have access to the whole DOM content. I think this fix is really creative and I think it's a good solution. I do worry though about making it mandatory for implementors who are trying to pre-render. I can see more instances of these I also wonder if we could reduce the need for slot-controller by utilizing the CSS :has() selector. For instance, if you're relying on hiding and showing certain pieces of the shadowroot based on what slots are in the lightdom, I think that could be a better use case for CSS :has() over slot-controller. It would remove the requirement for |
Very creative for sure. That said, I share Potters concerns about tackling it with attributes. Can you share an example or two of
Curious to know what that looks like and if a CSS solution like Potter touched on might be viable. 🤔 |
Light DOM CSS solves a different problem than this PR. Light DOM CSS is only for styling deeply nested children, since the alternative (slapping style attributes on children via the DOM API) is truly unpalatable. This PR is primarily about ponyfilling #slots = new SlotController(this, 'belly');
render() {
return html`
<div id="stomach" class="${classMap({ empty: this.#slots.isEmpty('belly') })}">
<belly-button>
<slot name="belly"></slot>
</div>
<!-- head, shoulders, knees, toes -->
`;
} This case shows how using slotcontroller we could hide or otherwise style the container for the belly slot when there's no slotted belly content. How would you handle this case with light dom css? You couldn't without exposing a shadow part. So why not just expose a shadow part then? That would be applying a solution in the element's design to solve a technical problem in the element's implementation. that's a severe inversion of priorities. The solution we're looking for is something like: #stomach:has(:has-slotted(*)) {
/* ... */
} but that's not quite ready yet, so we need a stopgap. |
Follow up to #2891
Lit-SSR forbids accessing DOM children when rendering the shadow root of an element server side, but we are permitted to access the attributes, so this PR adds ssr-hint attributes for slotted content, so that elements which use
SlotController
to render the shadowroot differently depending on which slots have content will work. Pages that load the SSR shim that don't solve this problem will be broken because of hydration mismatch errors. I've yet to find a workaround which can fix an element broken in that way after the fact.What I did
ssr-hint-has-slotted
andssr-hint-has-default-slot
attributesUsers doing SSR on the page would be required to ship source HTML with ssr hint attributes, for example (using pf-card)
Failure to add the
ssr-hint-*
attributes, or adding incorrect attributes (e.g. saying there's content for a slot when there isn't or vice versa) will result in a broken element.Automations could be written to apply those attributes to elements server-side prior to SSR'ing the page, e.g. in an eleventy transform.
Testing Instructions
npm run build cp core/pfe-core/controllers/slot-controller*.{js,d.ts} ../red-hat-design-system/node_modules/@patternfly/pfe-core/controllers
See also RedHat-UX/red-hat-design-system#2131, specifically
elements/rh-card/demo/darkest.html
Notes to Reviewers