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

chore: enable hydration for declarative shadow roots #10519

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

vladitasev
Copy link
Contributor

@vladitasev vladitasev commented Jan 10, 2025

Declarative shadow DOM

Currently UI5Element.ts always calls attachShadow in the constructor, which in turn always creates a new shadow root (and destroys the existing declarative shadow root, if provided).

This change introduces a small fix to not destroy declarative shadow roots.

Notes about using declarative shadow DOM

  1. Do not forget to pass all shadowRootOptions to the <template>, f.e. for Button.ts we have:
@customElement({
	...
	shadowRootOptions: { delegatesFocus: true },
})

therefore it needs:

<template shadowrootmode="open" shadowrootdelegatesfocus="true">...</template>

as opposed to the most commonly used:

<template shadowrootmode="open">...</template>
  1. The initial rendering will always be executed, and will ideally only attach event listeners (the pre-rendered HTML is expected to be correct)

  2. It's strongly recommended to use:

<style>
	*:not(:defined) {
		display: none;
	}
</style>

when rendering with declarative shadow DOM.

@vladitasev vladitasev changed the title chore: do not destroy declarative shadow roots chore: enable hydratation for declarative shadow roots Jan 10, 2025
@vladitasev vladitasev changed the title chore: enable hydratation for declarative shadow roots chore: enable hydration for declarative shadow roots Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant