Skip to content

Conversation

@quarkus
Copy link
Contributor

@quarkus quarkus commented Sep 4, 2025

Currently we have an animation frame between connection of an element and the first render cycle.

I ran into a bug today while rendering a Shadow Element as we actually attach the ShadowRoot on connected but actually render not until the requested update is performed.

That leaves the element in a state where the light dome is kind of "detached" from the DOM.

That leads to eg. nested elements having NO offsetParent and no dimensions at all:
screenshot_mh 2025-09-04 um 15 24 33

With this change i would like to keep the SR Attache and the first render in the same tick.

Is there any reason why we should not do it like this @eddyloewen !?

@quarkus quarkus marked this pull request as draft September 4, 2025 19:53
* @param {PropertyUpdateOptions} options
*/
update(options) {
let firstRender = this._options.shadowRender && !this.shadowRoot;
Copy link
Contributor

Choose a reason for hiding this comment

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

@quarkus this check will now run for every update cycle. There can be A LOT of update cycles... Is this ok performance wise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess we should set a simble "attached" flag somewhere, but yes, guess it makes sense to keep it as simple as possible.

Copy link
Contributor Author

@quarkus quarkus Sep 5, 2025

Choose a reason for hiding this comment

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

Hey @eddyloewen ! I challenged the idea but AI suggests that there is no performance to gain.

both boolean and the falsy check will be rather fast:
Accessing this.shadowRoot is a direct property lookup on the object, which is one of the fastest operations in JavaScript. It is a fundamental part of the object model and is highly optimized by browser engines.

It also pointed out that adding more flags will probably introduce new bugs which is probably also true :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ps.: i also moved it to the render function. maybe it makes more sense in combination with the adoptStyleSheets call.

if (firstRender) {
this.attachShadow({ mode: 'open' });
// adopt stylesheets
this.adoptStyleSheets();
Copy link
Contributor

Choose a reason for hiding this comment

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

@quarkus where does this come from? This call was not here before...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That actually comes from the "StyledElements" connectedCallback which we extend from here.

Since i moved the "attach" call here i have to somehow "retrigger" the adoption after the shadowroot is attached. Otherwise the styles are adopted into nohwere ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please check again @eddyloewen . I rearranged the code and also removed it from the StyledElements connected as it actually needs a root to make sense.

…n (initStyleAdoption) which makes things hopefully better to understand.

also removed the code from StyledElements connected as it needs a shadowRoot anyways to actually make sense.
@quarkus quarkus marked this pull request as ready for review September 10, 2025 04:56
@quarkus quarkus requested a review from eddyloewen September 10, 2025 04:57
@quarkus quarkus merged commit 52fcffd into main Oct 9, 2025
1 check passed
@quarkus quarkus deleted the feature/synchronus-shadow-root branch October 9, 2025 17:11
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.

4 participants