|
2 | 2 | <BaseErrorBoundary :theme="theme">
|
3 | 3 | <LoaderContent
|
4 | 4 | v-bind="{
|
5 |
| - content: !!content && patchedIsContent(content) && (!!fallback || firstLoad), |
| 5 | + content: |
| 6 | + !!content && patchedIsContent(content) && (!!fallback || firstLoad || hydrated), |
6 | 7 | errors,
|
7 | 8 | loading,
|
8 | 9 | refresh,
|
|
17 | 18 | :class="$attrs.class"
|
18 | 19 | >
|
19 | 20 | <slot
|
20 |
| - v-if="!!content && patchedIsContent(content) && (!!fallback || firstLoad)" |
| 21 | + v-if=" |
| 22 | + !!content && patchedIsContent(content) && (!!fallback || firstLoad || hydrated) |
| 23 | + " |
21 | 24 | v-bind="{ content, refresh, loading, errors }"
|
22 | 25 | ></slot>
|
23 | 26 | </LoaderContent>
|
|
108 | 111 | const useAsyncData: typeof useAsyncDataFn = internals?.useAsyncData ?? useAsyncDataFn;
|
109 | 112 |
|
110 | 113 | const firstLoad = ref(false);
|
111 |
| - const hydrated = ref(false); |
112 | 114 | /** Whether component was deactivated by keep-alive */
|
113 | 115 | const deactivated = ref(false);
|
114 | 116 |
|
115 |
| - const hydrateContent = computed({ |
116 |
| - get: () => (typeof fetchedContent !== "undefined" ? fetchedContent.value : undefined), |
117 |
| - set: (newContent) => { |
118 |
| - // prevent hydration |
119 |
| - if (deactivated.value) return; |
120 |
| - if (fetchedContent.value && !hydrated.value) return (hydrated.value = true); |
121 |
| - if (!props.preventAutoload && !firstLoad.value) return; |
122 |
| -
|
123 |
| - fetchedContent.value = newContent; |
124 |
| - }, |
125 |
| - }); |
126 |
| - const hydrateErrors = computed({ |
127 |
| - get: () => (typeof errors !== "undefined" ? errors.value : undefined), |
128 |
| - set: (newContent) => { |
129 |
| - // prevent hydration |
130 |
| - if (deactivated.value) return; |
131 |
| - if (errors.value && !hydrated.value) return (hydrated.value = true); |
132 |
| - if (!props.preventAutoload && !firstLoad.value) return; |
133 |
| -
|
134 |
| - errors.value = newContent; |
135 |
| - }, |
136 |
| - }); |
137 |
| -
|
138 | 117 | const {
|
139 |
| - data: fetchedContent, |
| 118 | + data: content, |
140 | 119 | pending: loading,
|
141 | 120 | error: errors,
|
142 | 121 | refresh,
|
|
182 | 161 |
|
183 | 162 | firstLoad.value = true;
|
184 | 163 |
|
185 |
| - return newData; |
| 164 | + return newData ?? props.fallback ?? null; |
186 | 165 | },
|
187 | 166 | {
|
188 | 167 | default: () => props.fallback,
|
|
191 | 170 | }
|
192 | 171 | );
|
193 | 172 |
|
194 |
| - const content = computed(() => fetchedContent.value ?? props.fallback); |
| 173 | + /** |
| 174 | + * Whether content was hydrated |
| 175 | + * By default, if firstLoad is not set but there is content, it means it was hydrated |
| 176 | + */ |
| 177 | + const hydrated = ref<boolean>(!props.fallback && !!content.value); |
| 178 | + const hydrateContent = computed({ |
| 179 | + get: () => (typeof content !== "undefined" ? content.value : undefined), |
| 180 | + set: (newContent) => { |
| 181 | + // prevent hydration |
| 182 | + if (deactivated.value) return; |
| 183 | + if (content.value && !hydrated.value) return (hydrated.value = true); |
| 184 | + if (!props.preventAutoload && !firstLoad.value) return; |
| 185 | +
|
| 186 | + content.value = newContent; |
| 187 | + }, |
| 188 | + }); |
| 189 | + const hydrateErrors = computed({ |
| 190 | + get: () => (typeof errors !== "undefined" ? errors.value : undefined), |
| 191 | + set: (newContent) => { |
| 192 | + // prevent hydration |
| 193 | + if (deactivated.value) return; |
| 194 | + if (errors.value && !hydrated.value) return (hydrated.value = true); |
| 195 | + if (!props.preventAutoload && !firstLoad.value) return; |
| 196 | +
|
| 197 | + errors.value = newContent; |
| 198 | + }, |
| 199 | + }); |
195 | 200 |
|
196 | 201 | function patchedIsContent(c?: T): boolean {
|
197 | 202 | return props.isContent?.(c) ?? !!c;
|
|
0 commit comments