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

Data State Inconsistency #1041

Closed
anatolzak opened this issue Mar 3, 2024 · 2 comments · Fixed by #1042
Closed

Data State Inconsistency #1041

anatolzak opened this issue Mar 3, 2024 · 2 comments · Fixed by #1042
Labels
bug Something isn't working

Comments

@anatolzak
Copy link
Contributor

anatolzak commented Mar 3, 2024

Describe the bug

There is currently an inconsistency in how we calculate the data-state attribute.

With Dialog Content and Overlay, Tooltip Content:

'data-state': $open ? 'open' : 'closed'

With the rest of the components (Link Preview Content, Menu Content, Popover Content, etc.):

'data-state': $isVisible ? 'open' : 'closed'

I believe that the data-state should be based on $open, because if we use forceVisible: true and always keep the content mounted, data-state will always be open.

The only place where this decision between $open and $isVisible matters, is when the user uses forceVisible: true, in which case if they unmount the component when $open is false and use a svelte transition, data-state will actually stay open because of how svelte internally freezes the component to transition it out. But if the user always leaves it as mounted and just changes the content's visibility, data-state should be closed, which is not currently the case with the codebase.

Now, if we agree that we should change the data-state based on $open, we need to make sure that we don't override styles set by floating-ui in certain components.

'data-state': $open ? 'open' : 'closed',
style: styleToString({
    display: $isVisible ? undefined : 'none',
}),

The above code would "rerender" every time the $open state changes, and if the user never unmounts the content, the styles will get reset to an empty string, thereby removing the styles set by floating-ui, which causes the component to jump. This was already fixed in the case of the tooltip content here #1010

The solution was to use the below code

'data-state': $open ? 'open' : 'closed',
style: $isVisible ? undefined : styleToString({ display: 'none' }),

... and to remove properties with undefined values returned from the tooltip content, because if we set style to undefined, svelte will also reset the styles set by floating-ui. So we needed to remove the style property altogether.

So since this will be a problem in all builders, we should remove properties with undefined values in the makeElement function.

Reproduction

Logs

No response

System Info

-

Severity

annoyance

@anatolzak anatolzak added the bug Something isn't working label Mar 3, 2024
@TGlide
Copy link
Member

TGlide commented Mar 3, 2024

I agree it should be based on open state. But display should be based on forceVisible too, meaning it should be based on isVisible

@anatolzak
Copy link
Contributor Author

anatolzak commented Mar 3, 2024

@TGlide 100%! I accidentally wrote that display should be based on $open. In my PR for the tooltip and in my PR that I just created for this issue, display is based on $isVisible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants