Skip to content

ui5-tabcontainer | svelte #8514

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

Closed
1 task done
ash-uncover opened this issue Mar 22, 2024 · 4 comments
Closed
1 task done

ui5-tabcontainer | svelte #8514

ash-uncover opened this issue Mar 22, 2024 · 4 comments
Assignees
Labels
author action bug This issue is a bug in the code Stale TOPIC Core

Comments

@ash-uncover
Copy link

Bug Description

ui5-tabcontainer is raising error when switching tab when used in svelte framework

Affected Component

ui5-tabcontainer

Expected Behaviour

we should be able to switch between tabs

Isolated Example

https://github.com/ash-uncover/ui5-webcomponents-svelte-issue

Steps to Reproduce

  1. Clone https://github.com/ash-uncover/ui5-webcomponents-svelte-issue
  2. npm install
  3. npm run dev -- --open
  4. try to switch from Tab1 to Tab2 > see error in the console

Log Output, Stack Trace or Screenshots

TabContainerTemplate.lit.ts:15 Uncaught TypeError: Cannot read properties of undefined (reading 'effectiveHidden')
at TabContainer2.block84 (TabContainerTemplate.lit.ts:15:278)
at TabContainer2.block013 (TabContainerTemplate.lit.ts:7:1425)
at executeTemplate (executeTemplate.ts:17:18)
at TabContainer2.render (UI5Element.ts:162:10)
at updateShadowRoot (updateShadowRoot.ts:21:26)
at TabContainer2._render (UI5Element.ts:707:4)
at renderImmediately (Render.ts:44:15)
at RenderQueue.process (RenderQueue.ts:64:4)
at Render.ts:67:30

Priority

High

UI5 Web Components Version

1.23.0

Browser

Chrome

Operating System

No response

Additional Context

No response

Organization

No response

Declaration

  • I’m not disclosing any internal or sensitive information.
@ash-uncover ash-uncover added the bug This issue is a bug in the code label Mar 22, 2024
@ash-uncover
Copy link
Author

Note that this is working fine when using pure client side rendering

@pskelin pskelin self-assigned this Mar 25, 2024
@pskelin
Copy link
Contributor

pskelin commented Mar 25, 2024

Svelte seems to remove attributes it didn't add during its hydration step. We have seen this with other frameworks too. This is what happens:

  1. Svelte sends the <ui5-tab> markup to the client
  2. The import @ui5/webcomponents/dist/Tab.js is executed and the custom element is defined
  3. The custom element adds a ui5-tab attribute to its host so the element becomes <ui5-tab ui5-tab>
  4. Svelte hydration runs and removes the ui5-tab attribute because it was not there on the server: <ui5-tab>
  5. Some logic that the TabContainer runs depends on this attribute being present and breaks

Basically the custom element logic runs before the hydration is what is causing the problem.

I couldn't find a way to modify the svelte behaviour other than turning off SSR completely. So instead as a workaround, if the custom element is defined after the hydration, adding the attribute by the custom element will be ok.

I tried this by making all imports dynamic, this way the define of each custom element will run a bit later. I change Main.svelte to this:

<script>
  import('@ui5/webcomponents/dist/Label.js')
  import('@ui5/webcomponents/dist/Tab.js')
  import('@ui5/webcomponents/dist/TabContainer')
</script>

This seems to fix the issue, but it is not 100% synchronized with the svelte hydration. It would be best if there is a svelte hook for running code after hydration, but I couldn't find any.

Please let me know if this works for you.

PS. there is a svelte issue without a resolution for this:
sveltejs/svelte#7379

And the code where the attributes are removed:
https://github.com/sveltejs/svelte/blob/svelte%404.2.12/packages/svelte/src/runtime/internal/dom.js#L706
This code seems fully refactored in the main branch, so perhaps the next svelte release will fix this...

Copy link

Hello, everyone! The issue has been inactive for 21 days. If there are still questions or comments, please feel free to continue the discussion. Inactive issues will be closed after 7 days!

@github-actions github-actions bot added the Stale label Nov 25, 2024
Copy link

github-actions bot commented Dec 2, 2024

Hello, everyone! The issue has been inactive for 28 days, so I am closing the issue.

@github-actions github-actions bot closed this as completed Dec 2, 2024
@github-project-automation github-project-automation bot moved this from New to Completed in Maintenance - Topic Core Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author action bug This issue is a bug in the code Stale TOPIC Core
Projects
Status: Completed
Development

No branches or pull requests

3 participants