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
Offcanvas responsive issues #1153
Comments
Hi @VividLemon! I get a Vue warn with
and
Can this help to find a fix? |
Could an own teleport wrapper node be a solution instead of teleport to body? <body>
<div id="app">...</div>
<div id="teleports"><!-- target teleports here --></div>
</body> |
@VividLemon like described in the official documentation of vue, we should consider to use an own DOM node: Avoid targeting body when using Teleports and SSR together - usually, will contain other server-rendered content which makes it impossible for Teleports to determine the correct starting location for hydration. Instead, prefer a dedicated container, e.g. Every bootstrap-vue component, that uses teleport, can be configured ( We have two possible solutions:
<ClientOnly>
<Teleport to="body">
...
</Teleport>
</ClientOnly>
<Teleport to="#teleported">
...
</Teleport> with ...
<body>
<div id="app"></div>
<div id="teleported"></div>
</body> SSR rendering does something like: teleported = context.teleports['#teleported']
...
// Replace <div id="teleported"> with <div id="teleported" data-server-rendered="true">${teleported} |
The issue described here is not related to the teleport. Nor will the teleport not work as intended. I'm not sure why the Vuejs documentation recommends that solution, as it will not work, period. The issue with teleports, in general, not just in SSR, is that the teleport can't grab an item that doesn't exist. Normally what will occur when trying to teleport to a VNode is that it will fail because it can't find it. Nuxt equally contains this issue as it can't teleport to something that doesn't exist yet. In Vue's case, there has been some discussion about bypassing this issue by passively waiting for the mounting point before triggering the teleport - ie it will detect when the mount point is available, then proceed to teleport to it. However, this was discussed many, many months ago, and has seen to action on it's delivery. In regards to the Vuejs documentation, like I said, it's completely opposite to what Nuxt will actually recommend
Despite all this, this is not the issue that is described here. The issue described here relates to the following flow:
For this behavior, if you are ABOVE a breakpoint threshold, the content will always be rendered. If you are below the threshold, the content will appear through a toggle button -- our vmodel.
However, this has massive ramifications for SSR. Since the server does not have a viewport, and thus doesn't have a breakpoint, if you render the content on a large screen, the node will look like this: <div
v-show="modelValue"
ref="element"
aria-modal="true"
role="dialog"
:class="computedClasses"
tabindex="-1"
aria-labelledby="offcanvasLabel"
data-bs-backdrop="false"
v-bind="$attrs"
@keyup.esc="hide('esc')"
>
<-- --!>
</div> Like I said, the viewport is 0 on the server, so the content is false. However, the client has a viewport above the threshold! So it will render it's content! <div
v-show="modelValue"
ref="element"
aria-modal="true"
role="dialog"
:class="computedClasses"
tabindex="-1"
aria-labelledby="offcanvasLabel"
data-bs-backdrop="false"
v-bind="$attrs"
@keyup.esc="hide('esc')"
>
CONTENT!
</div> So, if we make this change, there will be a hydration mismatch. The only solution is to always use client-only with this component. Which is not ideal as, specifically for SSR, a lot of the time you use an offcanvas solution for nav, So, the issue here does not have to do with the process of teleporting. It has to do with displaying content when there is a breakpoint, and when there is not. If you're getting a hydration mismatch, perhaps you should open a new issue with some examples. |
As always @VividLemon you describe the issue in great detail so we can understand the issue at hand! Is there anything here that sparks a solution: |
I believe I may have a solution |
Of course you have, you are a rockstar! |
I won't be able to release any of my fixes until qmhc/vite-plugin-dts#218 (comment) and my branch are fixed. |
Got it, regardless, progress is key, and awesome to here. I just found those links and thought they might be useful! |
While developing the documentation, it became apparent that there is an issue with attempting to use responsive, and model value together can cause hydration issues. Specifically if model value is true, and then you try to use responsive at the same time.
So, we need to think about some way to fix all problems at once while retaining the model value, and SSR compatibility.
The text was updated successfully, but these errors were encountered: