@@ -99,28 +99,35 @@ export function setupLoaderGuard({
99
99
100
100
// we only add async modules because otherwise the component doesn't have any loaders and the user should add
101
101
// them with the `loaders` array
102
- if ( isAsyncModule ( component ) ) {
103
- const promise = component ( ) . then (
104
- ( viewModule : Record < string , unknown > ) => {
105
- for ( const exportName in viewModule ) {
106
- const exportValue = viewModule [ exportName ]
107
-
108
- if ( isDataLoader ( exportValue ) ) {
109
- record . meta [ LOADER_SET_KEY ] ! . add ( exportValue )
110
- }
111
- }
112
- if ( Array . isArray ( viewModule . __loaders ) ) {
113
- for ( const loader of viewModule . __loaders ) {
114
- if ( isDataLoader ( loader ) ) {
115
- record . meta [ LOADER_SET_KEY ] ! . add ( loader )
116
- }
117
- }
102
+ const promise = (
103
+ isAsyncModule ( component )
104
+ ? component ( )
105
+ : // we also support __loaders exported as an option to get around some temporary limitations
106
+ Promise . resolve (
107
+ component as Record < string , unknown > | ( ( ) => unknown )
108
+ )
109
+ ) . then ( ( viewModule ) => {
110
+ // avoid checking functional components
111
+ if ( typeof viewModule === 'function' ) return
112
+
113
+ for ( const exportName in viewModule ) {
114
+ const exportValue = viewModule [ exportName ]
115
+
116
+ if ( isDataLoader ( exportValue ) ) {
117
+ record . meta [ LOADER_SET_KEY ] ! . add ( exportValue )
118
+ }
119
+ }
120
+ // TODO: remove once nuxt doesn't wrap with `e => e.default` async pages
121
+ if ( Array . isArray ( viewModule . __loaders ) ) {
122
+ for ( const loader of viewModule . __loaders ) {
123
+ if ( isDataLoader ( loader ) ) {
124
+ record . meta [ LOADER_SET_KEY ] ! . add ( loader )
118
125
}
119
126
}
120
- )
127
+ }
128
+ } )
121
129
122
- lazyLoadingPromises . push ( promise )
123
- }
130
+ lazyLoadingPromises . push ( promise )
124
131
}
125
132
}
126
133
}
0 commit comments