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

ref should not provide element when disconnected #4622

Open
sorvell opened this issue Apr 13, 2024 · 0 comments
Open

ref should not provide element when disconnected #4622

sorvell opened this issue Apr 13, 2024 · 0 comments

Comments

@sorvell
Copy link
Member

sorvell commented Apr 13, 2024

Which package(s) are affected?

Lit Core (lit / lit-html / lit-element / reactive-element)

Description

The ref directive supplies an element when it runs update and it is in a disconnected state. This does not make sense since ref supplies undefined when disconnected and the element again when reconnected. Since this behavior implies that ref is intended to supply undefined when disconnected, it's incorrect for this to change while it is disconnected.

This can cause practical problems if code depends on installing/removing behavior based on connection state. See discord discussion.

Note also that checking refElement.isConnected is not a workaround since directives are run in a connected state regardless of whether or not the host context is connected.

Reproduction

In the repro example here https://lit.dev/playground/#gist=fe6d7deeba80b76873eb057819ed2bc4

  1. open the console
  2. click the remove button
  3. click the increment button
  4. click the add button

Note that:
A. After (3) the ref callback is supplied when an element. This is unexpected.
B. After (4) the ref callback gets undefined and then the element. This is unexpected.

Workaround

Gate behavior on the host's connection state.

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

3.x

Browser/OS/Node environment

All

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant