Skip to content

Commit ee7e2de

Browse files
committed
fix: prevent flicker on hard refresh
1 parent 2ca089f commit ee7e2de

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

app/components/PackageManagerSelect.vue

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ useEventListener('scroll', close, true)
2424
const inputId = useId()
2525
const listboxId = `${inputId}-listbox`
2626
27-
const pm = computed(() => {
28-
return packageManagers.find(p => p.id === selectedPM.value) ?? packageManagers[0]
29-
})
30-
3127
function toggle() {
3228
if (isOpen.value) {
3329
close()
@@ -100,8 +96,20 @@ function handleKeydown(event: KeyboardEvent) {
10096
@click="toggle"
10197
@keydown="handleKeydown"
10298
>
103-
<span class="inline-block h-3 w-3" :class="pm.icon" aria-hidden="true" />
104-
<span>{{ pm.label }}</span>
99+
<template v-for="pmOption in packageManagers" :key="pmOption.id">
100+
<span
101+
class="inline-block h-3 w-3 pm-select-content"
102+
:class="pmOption.icon"
103+
:data-pm-select="pmOption.id"
104+
aria-hidden="true"
105+
/>
106+
<span
107+
class="pm-select-content"
108+
:data-pm-select="pmOption.id"
109+
:aria-hidden="pmOption.id !== selectedPM"
110+
>{{ pmOption.label }}</span
111+
>
112+
</template>
105113
<span
106114
class="i-carbon:chevron-down w-3 h-3"
107115
:class="[
@@ -162,3 +170,23 @@ function handleKeydown(event: KeyboardEvent) {
162170
</Transition>
163171
</Teleport>
164172
</template>
173+
174+
<style>
175+
:root[data-pm] .pm-select-content {
176+
display: none;
177+
}
178+
179+
:root[data-pm='npm'] [data-pm-select='npm'],
180+
:root[data-pm='pnpm'] [data-pm-select='pnpm'],
181+
:root[data-pm='yarn'] [data-pm-select='yarn'],
182+
:root[data-pm='bun'] [data-pm-select='bun'],
183+
:root[data-pm='deno'] [data-pm-select='deno'],
184+
:root[data-pm='vlt'] [data-pm-select='vlt'] {
185+
display: inline-block;
186+
}
187+
188+
/* Fallback: when no data-pm is set, npm is selected by default */
189+
:root:not([data-pm]) .pm-select-content:not([data-pm-select='npm']) {
190+
display: none;
191+
}
192+
</style>

0 commit comments

Comments
 (0)