Skip to content
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

fix: omit value property of isHydrated in template #681

Merged
merged 1 commit into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/publish/PublishAttachment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const toggleApply = () => {
v-if="removable"
:aria-label="$t('attachment.remove_label')"
hover:bg="gray/40" transition-100 p-1 rounded-5 cursor-pointer
:class="[isHydrated.value && isSmallScreen ? '' : 'op-0 group-hover:op-100hover:']"
:class="[isHydrated && isSmallScreen ? '' : 'op-0 group-hover:op-100hover:']"
mix-blend-difference
@click="$emit('remove')"
>
<div i-ri:close-line text-3 :class="[isHydrated.value && isSmallScreen ? 'text-6' : 'text-3']" />
<div i-ri:close-line text-3 :class="[isHydrated && isSmallScreen ? 'text-6' : 'text-3']" />
</div>
</div>
<div absolute right-2 bottom-2>
Expand Down
14 changes: 4 additions & 10 deletions composables/hydration.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
export const isHydrated = computed(() => {
if (process.server)
return { value: false }
export const isHydrated = ref(false)

if (!process.server) {
const nuxtApp = useNuxtApp()
if (!nuxtApp.isHydrating)
return { value: false }

const hydrated = ref(false)
nuxtApp.hooks.hookOnce('app:suspense:resolve', () => {
hydrated.value = true
isHydrated.value = true
})
return hydrated
})
}
4 changes: 2 additions & 2 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const wideLayout = computed(() => route.meta.wideLayout ?? false)
<slot />
</div>
<div sm:hidden sticky left-0 right-0 bottom-0 z-10 bg-base pb="[env(safe-area-inset-bottom)]" transition="padding 20">
<CommonOfflineChecker :small-screen="isHydrated.value" />
<NavBottom v-if="isHydrated.value" />
<CommonOfflineChecker :small-screen="isHydrated" />
<NavBottom v-if="isHydrated" />
</div>
</div>
<aside v-if="!wideLayout" class="hidden sm:none lg:block w-1/4 zen-hide">
Expand Down
2 changes: 1 addition & 1 deletion pages/[[server]]/explore/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ useHeadFixed({
</script>

<template>
<CommonAlert v-if="isHydrated.value && !hideNewsTips" @close="hideNewsTips = true">
<CommonAlert v-if="isHydrated && !hideNewsTips" @close="hideNewsTips = true">
<p>{{ $t('tooltip.explore_posts_intro') }}</p>
</CommonAlert>
<!-- TODO: Tabs for trending statuses, tags, and links -->
Expand Down
2 changes: 1 addition & 1 deletion pages/[[server]]/explore/links.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ useHeadFixed({
</script>

<template>
<CommonAlert v-if="isHydrated.value && !hideNewsTips" @close="hideNewsTips = true">
<CommonAlert v-if="isHydrated && !hideNewsTips" @close="hideNewsTips = true">
<p>{{ $t('tooltip.explore_links_intro') }}</p>
</CommonAlert>

Expand Down
2 changes: 1 addition & 1 deletion pages/[[server]]/explore/tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ useHeadFixed({
</script>

<template>
<CommonAlert v-if="isHydrated.value && !hideTagsTips && data && data.length" @close="hideTagsTips = true">
<CommonAlert v-if="isHydrated && !hideTagsTips && data && data.length" @close="hideTagsTips = true">
<p>{{ $t('tooltip.explore_tags_intro') }}</p>
</CommonAlert>

Expand Down
4 changes: 2 additions & 2 deletions pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const isRootPath = computedEager(() => route.name === 'settings')
</template>
<div xl:w-97 lg:w-78 w-full>
<SettingsNavItem
v-show="currentUser"
:command="!!currentUser"
v-if="isHydrated && currentUser "
command
icon="i-ri:user-line"
:text="$t('settings.profile.label')"
to="/settings/profile"
Expand Down
2 changes: 2 additions & 0 deletions pages/settings/profile/appearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const { submit, submitting } = submitter(async ({ dirtyFields }) => {
<!-- banner -->
<div of-hidden bg="gray-500/20" aspect="3">
<CommonInputImage
v-if="isHydrated"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are warnings of hydration because onlineSrc.header is empty on the server side.

ref="elInputImage"
v-model="form.header"
:original="onlineSrc.header"
Expand All @@ -80,6 +81,7 @@ const { submit, submitting } = submitter(async ({ dirtyFields }) => {
<!-- avatar -->
<div px-4>
<CommonInputImage
v-if="isHydrated"
v-model="form.avatar"
:original="onlineSrc.avatar"
mt--10
Expand Down