-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Won't work with Suspense #584
Comments
Looks like a regression in Vue, this used to work |
Duplicate of vuejs/core#2215 |
Apologies for posting vuejs/vue-router-next#3369 in the wrong repo. It's a regression by design, it was part of vuejs/core#2099. This is a very unfortunate change, and I'd gladly take any guidance from @posva regarding how to load routes that are async setup.
|
@posva I'm not 100% confident closing as a duplicate is the right call. Suspense is experimental but there is no signal from the team whether this will change or not. |
Hi @posva vuejs/core#2215 has been fixed. But still I can confirm the issue with vue-router. It's really convenient to load all the necessary data asynchronously within the Hope this will be fixed. @jods4 Have you found any workaround? |
Proper integration with Suspense will likely go through an RFC to support the fallback slot. It might also need changes in Vue core. That being said, the initial issue was fixed: the code displays the view instead of erroring. The nested fallback not displaying is still a native behavior in Suspense (which is still experimental) that will need further research |
@posva I haven't had time to try the fixes in my project but I intend to and I'm a bit confused by the last 2 comments. @yaquawa Yes, I have a workaround in place in my project but it's not nice. <template>
Template as usual
</template>
<script>
// Notice I'm not exporting yet
const page = defineComponent({
// Your component as usual
async setup() { }
});
// This wraps the component in its own Suspense
export default suspenseWrapper(page);
</script> And so, instead of having a |
Hi @jods4, thanks for the sample code!! Oh? really?? I'm using vue-loader to load the *.vue files. So the exported object in the |
@yaquawa You are right, my code is actually slightly different because you can't do the wrapping like that in the SFC. export default <RouteRecordRaw[]>[
{ path: "/", component: suspenseHack(Home) },
// etc.
] Conveniently, this is the only file where The full code for the wrapper is here: // HACK: this is a dirty workaround for Suspense not working
// with components that are not its direct children
// since https://github.com/vuejs/vue-next/pull/2099
// See also this discussion:
// https://github.com/vuejs/vue-next/issues/2215
// Could be better supported with direct Router support:
// https://github.com/vuejs/vue-router-next/issues/584
import { Component, FunctionalComponent, h, Suspense } from "vue";
export function suspenseHack(component: Component) {
const wrapper: FunctionalComponent = () =>
h(Suspense, null, {
default() {
return h(component);
},
fallback() {
return h("app-loading"); // <-- REPLACE THIS WITH YOUR OWN FALLBACK
},
});
wrapper.displayName = "SuspenseHack";
return wrapper;
} Please note that I haven't tested this code with versions of Vue that contain the fix for this issue. |
@jods4 Thanks for the sample code!! Fantastic! |
I encountered some problems: |
@paprika135 This issue has been closed, the hack above has not been required for many Vue releases now. |
Version
4.0.0-rc.2
Reproduction link
https://codesandbox.io/s/modest-butterfly-ih1jr?file=/src/App.vue
Steps to reproduce
This won't work
The text was updated successfully, but these errors were encountered: