Skip to content

Commit c350721

Browse files
authored
perf: prefere shallowRef instead deep ref if possible (#142)
1 parent 5c4d900 commit c350721

26 files changed

Lines changed: 99 additions & 143 deletions

app/components/AppFooter.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<script setup lang="ts">
2-
const isMounted = ref(false)
3-
const isVisible = ref(false)
4-
const isScrollable = ref(true)
5-
const lastScrollY = ref(0)
6-
const footerRef = ref<HTMLElement>()
2+
const isMounted = shallowRef(false)
3+
const isVisible = shallowRef(false)
4+
const isScrollable = shallowRef(true)
5+
const lastScrollY = shallowRef(0)
6+
const footerRef = useTemplateRef('footerRef')
77
88
// Check if CSS scroll-state container queries are supported
99
// Once this becomes baseline, we can remove the JS scroll handling entirely
10-
const supportsScrollStateQueries = ref(false)
10+
const supportsScrollStateQueries = useSupported(() => {
11+
return isMounted.value && CSS.supports('container-type', 'scroll-state')
12+
})
1113
1214
function checkScrollable() {
1315
return document.documentElement.scrollHeight > window.innerHeight
@@ -52,10 +54,6 @@ useEventListener('scroll', onScroll, { passive: true })
5254
useEventListener('resize', onResize, { passive: true })
5355
5456
onMounted(() => {
55-
// Feature detect CSS scroll-state container queries (Chrome 133+)
56-
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/@container#scroll-state_container_descriptors
57-
supportsScrollStateQueries.value = CSS.supports('container-type', 'scroll-state')
58-
5957
nextTick(() => {
6058
lastScrollY.value = window.scrollY
6159
isScrollable.value = checkScrollable()

app/components/AppTooltip.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const props = defineProps<{
66
position?: 'top' | 'bottom' | 'left' | 'right'
77
}>()
88
9-
const isVisible = ref(false)
9+
const isVisible = shallowRef(false)
1010
const tooltipId = useId()
1111
1212
const positionClasses: Record<string, string> = {

app/components/ClaimPackageModal.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ const {
1919
} = useConnector()
2020
2121
// Fetch name availability when modal opens
22-
const checkResult = ref<CheckNameResult | null>(null)
22+
const checkResult = shallowRef<CheckNameResult | null>(null)
2323
24-
const isChecking = ref(false)
25-
const isPublishing = ref(false)
26-
const publishError = ref<string | null>(null)
27-
const publishSuccess = ref(false)
24+
const isChecking = shallowRef(false)
25+
const isPublishing = shallowRef(false)
26+
const publishError = shallowRef<string | null>(null)
27+
const publishSuccess = shallowRef(false)
2828
2929
async function checkAvailability() {
3030
isChecking.value = true
@@ -125,7 +125,7 @@ const previewPackageJson = computed(() => {
125125
}
126126
})
127127
128-
const connectorModalOpen = ref(false)
128+
const connectorModalOpen = shallowRef(false)
129129
</script>
130130

131131
<template>

app/components/CodeMobileTreeDrawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defineProps<{
77
baseUrl: string
88
}>()
99
10-
const isOpen = ref(false)
10+
const isOpen = shallowRef(false)
1111
1212
// Close drawer on navigation
1313
const route = useRoute()

app/components/CodeViewer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const emit = defineEmits<{
99
lineClick: [lineNum: number, event: MouseEvent]
1010
}>()
1111
12-
const codeRef = ref<HTMLElement>()
12+
const codeRef = useTemplateRef('codeRef')
1313
1414
// Generate line numbers array
1515
const lineNumbers = computed(() => {

app/components/ConnectorModal.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const open = defineModel<boolean>('open', { default: false })
44
const { isConnected, isConnecting, npmUser, error, hasOperations, connect, disconnect } =
55
useConnector()
66
7-
const tokenInput = ref('')
8-
const portInput = ref('31415')
9-
const copied = ref(false)
7+
const tokenInput = shallowRef('')
8+
const portInput = shallowRef('31415')
9+
const copied = shallowRef(false)
1010
1111
async function handleConnect() {
1212
const port = Number.parseInt(portInput.value, 10) || 31415

app/components/ConnectorStatus.client.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
const { isConnected, isConnecting, npmUser, error, activeOperations, hasPendingOperations } =
33
useConnector()
44
5-
const showModal = ref(false)
6-
const showTooltip = ref(false)
5+
const showModal = shallowRef(false)
6+
const showTooltip = shallowRef(false)
77
88
const statusText = computed(() => {
99
if (isConnecting.value) return 'connecting…'

app/components/OperationsQueue.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const {
2121
refreshState,
2222
} = useConnector()
2323
24-
const isExecuting = ref(false)
25-
const otpInput = ref('')
24+
const isExecuting = shallowRef(false)
25+
const otpInput = shallowRef('')
2626
2727
/** Check if any active operation needs OTP */
2828
const hasOtpFailures = computed(() =>

app/components/OrgMembersPanel.vue

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ const {
2121
} = useConnector()
2222
2323
// Members data: { username: role }
24-
const members = ref<Record<string, 'developer' | 'admin' | 'owner'>>({})
25-
const isLoading = ref(false)
26-
const error = ref<string | null>(null)
24+
const members = shallowRef<Record<string, 'developer' | 'admin' | 'owner'>>({})
25+
const isLoading = shallowRef(false)
26+
const error = shallowRef<string | null>(null)
2727
2828
// Team membership data: { teamName: [members] }
2929
const teamMembers = ref<Record<string, string[]>>({})
30-
const isLoadingTeams = ref(false)
30+
const isLoadingTeams = shallowRef(false)
3131
3232
// Search/filter
33-
const searchQuery = ref('')
34-
const filterRole = ref<'all' | 'developer' | 'admin' | 'owner'>('all')
35-
const filterTeam = ref<string | null>(null)
36-
const sortBy = ref<'name' | 'role'>('name')
37-
const sortOrder = ref<'asc' | 'desc'>('asc')
33+
const searchQuery = shallowRef('')
34+
const filterRole = shallowRef<'all' | 'developer' | 'admin' | 'owner'>('all')
35+
const filterTeam = shallowRef<string | null>(null)
36+
const sortBy = shallowRef<'name' | 'role'>('name')
37+
const sortOrder = shallowRef<'asc' | 'desc'>('asc')
3838
3939
// Add member form
40-
const showAddMember = ref(false)
41-
const newUsername = ref('')
42-
const newRole = ref<'developer' | 'admin' | 'owner'>('developer')
43-
const newTeam = ref<string>('') // Empty string means "developers" (default)
44-
const isAddingMember = ref(false)
40+
const showAddMember = shallowRef(false)
41+
const newUsername = shallowRef('')
42+
const newRole = shallowRef<'developer' | 'admin' | 'owner'>('developer')
43+
const newTeam = shallowRef<string>('') // Empty string means "developers" (default)
44+
const isAddingMember = shallowRef(false)
4545
4646
// Role priority for sorting
4747
const rolePriority = { owner: 0, admin: 1, developer: 2 }

app/components/OrgTeamsPanel.vue

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ const {
1717
} = useConnector()
1818
1919
// Teams data
20-
const teams = ref<string[]>([])
20+
const teams = shallowRef<string[]>([])
2121
const teamUsers = ref<Record<string, string[]>>({})
22-
const isLoadingTeams = ref(false)
22+
const isLoadingTeams = shallowRef(false)
2323
const isLoadingUsers = ref<Record<string, boolean>>({})
24-
const error = ref<string | null>(null)
24+
const error = shallowRef<string | null>(null)
2525
2626
// Org members (to check if user needs to be added to org first)
27-
const orgMembers = ref<Record<string, 'developer' | 'admin' | 'owner'>>({})
27+
const orgMembers = shallowRef<Record<string, 'developer' | 'admin' | 'owner'>>({})
2828
2929
// Search/filter
30-
const searchQuery = ref('')
31-
const sortBy = ref<'name' | 'members'>('name')
32-
const sortOrder = ref<'asc' | 'desc'>('asc')
30+
const searchQuery = shallowRef('')
31+
const sortBy = shallowRef<'name' | 'members'>('name')
32+
const sortOrder = shallowRef<'asc' | 'desc'>('asc')
3333
3434
// Expanded teams (to show members)
3535
const expandedTeams = ref<Set<string>>(new Set())
3636
3737
// Create team form
38-
const showCreateTeam = ref(false)
39-
const newTeamName = ref('')
40-
const isCreatingTeam = ref(false)
38+
const showCreateTeam = shallowRef(false)
39+
const newTeamName = shallowRef('')
40+
const isCreatingTeam = shallowRef(false)
4141
4242
// Add user form (per team)
43-
const showAddUserFor = ref<string | null>(null)
44-
const newUserUsername = ref('')
45-
const isAddingUser = ref(false)
43+
const showAddUserFor = shallowRef<string | null>(null)
44+
const newUserUsername = shallowRef('')
45+
const isAddingUser = shallowRef(false)
4646
4747
// Filtered and sorted teams
4848
const filteredTeams = computed(() => {

0 commit comments

Comments
 (0)