Skip to content

Commit c5def90

Browse files
committed
feat: improve package manager detection on hydration
1 parent 483db0b commit c5def90

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

app/composables/useSelectedPackageManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export const useSelectedPackageManager = createSharedComposable(
1212

1313
// Sync to data-pm attribute on the client
1414
if (import.meta.client) {
15+
const queryPM = new URLSearchParams(window.location.search).get('pm')
16+
if (queryPM && packageManagers.some(pm => pm.id === queryPM)) {
17+
pm.value = queryPM as PackageManagerId
18+
}
1519
// Watch for changes and update the attribute
1620
watch(
1721
pm,

app/utils/prehydrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function initPreferencesOnPrehydrate() {
4242
let pm = 'npm'
4343

4444
// Support package manager preference in query string (for example, ?pm=pnpm)
45-
const queryPM = new URLSearchParams(document.location.search).get('pm')
45+
const queryPM = new URLSearchParams(window.location.search).get('pm')
4646
if (queryPM && validPMs.has(queryPM)) {
4747
pm = queryPM
4848
localStorage.setItem('npmx-pm', pm)

0 commit comments

Comments
 (0)