Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nicholasrice
Copy link
Contributor

This PR implements a public readonly property, shadowRoot, on the HTMLElement class defined in the dom-shim. This property will evaluate to the object created and returned by attachShadow() when attachShadow() is invoked with an open shadow root mode (host.attachShadow({mode: "open"}). Otherwise, shadowRoot will evaluate to null. This behavior is intended to match the DOM behavior defined here.

Let me know if changes are need; I'm happy to make any updates. I've also added one question inline that should probably get attention before merging. Thanks in advance!

Fixes #2652

@changeset-bot
Copy link

changeset-bot bot commented Mar 23, 2022

🦋 Changeset detected

Latest commit: 7f2e51a

The changes in this PR will be included in the next version bump.

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

@google-cla
Copy link

google-cla bot commented Mar 23, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

}
attachShadow() {
return {host: this};
attachShadow(init?: ShadowRootInit) {
Copy link
Contributor Author

@nicholasrice nicholasrice Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this init configuration as an optional param because I believe this would technically be a breaking change if it were required, even though the platform requires the init argument. I'm happy to update this to align with the platform if that is preferred.

Copy link
Member

@aomarks aomarks Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably just make it required, to match the platform. It seems like it would be unusual to be calling this method only in an SSR context -- it will usually be called by a library that is already web compatible. So I think we can make it required without issuing a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I'll leave this thread open so it's easier to find for other reviewers, in case they have thoughts.

Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the PR!

}
attachShadow() {
return {host: this};
attachShadow(init?: ShadowRootInit) {
Copy link
Member

@aomarks aomarks Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably just make it required, to match the platform. It seems like it would be unusual to be calling this method only in an SSR context -- it will usually be called by a library that is already web compatible. So I think we can make it required without issuing a breaking change.

value,
}));
}
#shadowRoot: null | ShadowRoot = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to use private _shadowRoot here, because AFAIK we haven't been using native class fields anywhere in our code base so far. And since we're targeting ES2020 still, the output is a little gnarly (https://www.typescriptlang.org/play?target=7#code/MYGwhgzhAEBmD29oG8CwAoa0DEAjMATtALzQB2AriCANwYZYLwAUAlCg1tAQKYAuFAmWh8AFgEsIAOjyE6maAF8MioA).

@justinfagnani WDYT about starting to use native class fields in our tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, renamed.

@aomarks
Copy link
Member

aomarks commented Mar 23, 2022

No Changeset found

Please run npx changeset in the top-level of the git repo, and mark @lit-labs/ssr as having a minor bump, with a brief description.

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

Please read and sign the Google CLA (if you agree!), see https://github.com/lit/lit/pull/2662/checks?check_run_id=5668663752 for details.

@aomarks aomarks merged commit 1d51ed8 into lit:main Mar 25, 2022
@aomarks
Copy link
Member

aomarks commented Mar 25, 2022

Thanks for the PR!

This was referenced Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ssr] Consider supporting HTMLElement.shadowRoot in SSR dom-shim.

2 participants