Finally (???) fix the hydration issues with a markdown renderer in SSR
This commit is contained in:
parent
cbef6d1289
commit
6550042751
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<HoverPopup @before-show="fetch" :class="[{'is-loaded': fetched}, file?.type === 'Markdown' ? 'overflow-auto' : 'overflow-hidden']">
|
<HoverPopup @before-show="fetch" :class="[{'is-loaded': fetched}, file?.type === 'Markdown' ? 'overflow-auto' : 'overflow-hidden']">
|
||||||
<template #content>
|
<template #content>
|
||||||
<Suspense>
|
<Suspense suspensible>
|
||||||
<div v-if="pending" class="loading w-[550px] h-[450px]"></div>
|
<div v-if="pending" class="loading w-[550px] h-[450px]"></div>
|
||||||
<template v-else-if="!!file">
|
<template v-else-if="!!file">
|
||||||
<div v-if="file.type === 'Markdown'" class="p-6 ms-6">
|
<div v-if="file.type === 'Markdown'" class="p-6 ms-6">
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
</div>
|
</div>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</template>
|
</template>
|
||||||
<slot></slot>
|
<template #default><slot name="default"></slot></template>
|
||||||
</HoverPopup>
|
</HoverPopup>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<Suspense>
|
<Suspense suspensible>
|
||||||
<NuxtLink no-prefetch class="text-accent-blue inline-flex items-center" v-if="data && data[0] && status !== 'pending'"
|
<NuxtLink no-prefetch class="text-accent-blue inline-flex items-center" v-if="data && data[0]"
|
||||||
:to="{ path: `/explorer/${project}/${data[0].path}`, hash: hash }" :class="class">
|
:to="{ path: `/explorer/${project}/${data[0].path}`, hash: hash }" :class="class">
|
||||||
<PreviewContent :project="project" :path="data[0].path" :anchor="hash">
|
<PreviewContent :project="project" :path="data[0].path" :anchor="hash">
|
||||||
<div class="inline-flex items-center">
|
<template #default>
|
||||||
<slot v-bind="$attrs"></slot>
|
<slot v-bind="$attrs"></slot>
|
||||||
<Icon class="w-4 h-4 inline-block" v-if="data && data[0] && data[0].type !== 'Markdown'" :height="20" :width="20"
|
<Icon class="w-4 h-4 inline-block" v-if="data && data[0] && data[0].type !== 'Markdown'" :height="20" :width="20"
|
||||||
:icon="`icons/link-${data[0].type.toLowerCase()}`" />
|
:icon="`icons/link-${data[0].type.toLowerCase()}`" />
|
||||||
</div>
|
</template>
|
||||||
</PreviewContent>
|
</PreviewContent>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<NuxtLink no-prefetch v-else-if="href" :to="href" :class="class" class="text-accent-blue inline-flex items-center">
|
<NuxtLink no-prefetch v-else-if="href" :to="href" :class="class" class="text-accent-blue inline-flex items-center">
|
||||||
|
|
@ -33,32 +33,18 @@ const props = defineProps({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const nuxt = useNuxtApp();
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { hash, pathname, protocol } = parseURL(props.href);
|
const { hash, pathname, protocol } = parseURL(props.href);
|
||||||
const project = computed(() => parseInt(Array.isArray(route.params.projectId) ? '0' : route.params.projectId));
|
const project = computed(() => parseInt(Array.isArray(route.params.projectId) ? '0' : route.params.projectId));
|
||||||
const key = computed(() => `file:${project.value}:%${pathname}`);
|
const data = ref();
|
||||||
|
|
||||||
const { data, status, execute } = await useFetch(`/api/project/${project.value}/file`, {
|
|
||||||
method: 'GET',
|
|
||||||
query: {
|
|
||||||
search: `%${pathname}`
|
|
||||||
},
|
|
||||||
transform: (data) => data?.map(e => ({ path: e.path, type: e.type })),
|
|
||||||
key: key.value,
|
|
||||||
ignoreResponseError: true,
|
|
||||||
immediate: false,
|
|
||||||
server: false,
|
|
||||||
dedupe: 'defer'
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!!pathname && !protocol)
|
if(!!pathname && !protocol)
|
||||||
{
|
{
|
||||||
await execute();
|
data.value = await $fetch(`/api/project/${project.value}/file`, {
|
||||||
if(data.value === null && status.value === 'idle')
|
query: {
|
||||||
{
|
search: `%${pathname}`
|
||||||
data.value = nuxt.payload.data[key.value] ?? nuxt.static.data[key.value];
|
},
|
||||||
status.value = 'success';
|
ignoreResponseError: true,
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -22,9 +22,6 @@ export default defineCachedEventHandler(async (e) => {
|
||||||
const criteria: Record<string, any> = { $project: project, $tag: tag };
|
const criteria: Record<string, any> = { $project: project, $tag: tag };
|
||||||
|
|
||||||
const db = useDatabase();
|
const db = useDatabase();
|
||||||
|
|
||||||
console.log(`SELECT * FROM explorer_tags WHERE ${where.join(" and ")}`, criteria);
|
|
||||||
|
|
||||||
const content = db.query(`SELECT * FROM explorer_tags WHERE ${where.join(" and ")}`).get(criteria) as Tag;
|
const content = db.query(`SELECT * FROM explorer_tags WHERE ${where.join(" and ")}`).get(criteria) as Tag;
|
||||||
|
|
||||||
if(content !== undefined)
|
if(content !== undefined)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue