diff --git a/packages/vant-cli/src/common/constant.ts b/packages/vant-cli/src/common/constant.ts index c46587f57..4cdc78822 100644 --- a/packages/vant-cli/src/common/constant.ts +++ b/packages/vant-cli/src/common/constant.ts @@ -1,7 +1,6 @@ import { get } from 'lodash-es'; import { existsSync, readFileSync } from 'fs'; -import { createRequire } from 'module'; -import { fileURLToPath } from 'url'; +import { fileURLToPath, pathToFileURL } from 'url'; import { join, dirname, isAbsolute } from 'path'; function findRootDir(dir: string): string { @@ -58,11 +57,10 @@ export function getPackageJson() { } async function getVantConfigAsync() { - const require = createRequire(import.meta.url); - delete require.cache[VANT_CONFIG_FILE]; - try { - return (await import(VANT_CONFIG_FILE)).default; + // https://github.com/nodejs/node/issues/31710 + // absolute file paths don't work on Windows + return (await import(pathToFileURL(VANT_CONFIG_FILE).href)).default; } catch (err) { return {}; } diff --git a/packages/vant-use/changelog.md b/packages/vant-use/changelog.md index 096069f8c..312928572 100644 --- a/packages/vant-use/changelog.md +++ b/packages/vant-use/changelog.md @@ -1,5 +1,9 @@ # Changelog +## v1.3.4 + +- Fix useClickAway failed in SSR + ### v1.3.3 - Allow to call useWindowSize outside setup @@ -7,7 +11,7 @@ ### v1.3.2 --Remove passive event polyfill +- Remove passive event polyfill ### v1.3.1 diff --git a/packages/vant-use/package.json b/packages/vant-use/package.json index 6d7a0a862..835b8d421 100644 --- a/packages/vant-use/package.json +++ b/packages/vant-use/package.json @@ -1,6 +1,6 @@ { "name": "@vant/use", - "version": "1.3.3", + "version": "1.3.4", "description": "Vant Composition API", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", diff --git a/packages/vant-use/src/useClickAway/index.ts b/packages/vant-use/src/useClickAway/index.ts index 8a936eef7..b36312dba 100644 --- a/packages/vant-use/src/useClickAway/index.ts +++ b/packages/vant-use/src/useClickAway/index.ts @@ -1,4 +1,5 @@ import { Ref, unref } from 'vue'; +import { inBrowser } from '../utils'; import { useEventListener } from '../useEventListener'; export type UseClickAwayOptions = { @@ -10,6 +11,10 @@ export function useClickAway( listener: EventListener, options: UseClickAwayOptions = {} ) { + if (!inBrowser) { + return; + } + const { eventName = 'click' } = options; const onClick = (event: Event) => { diff --git a/packages/vant/package.json b/packages/vant/package.json index cb106e727..cd1019e13 100644 --- a/packages/vant/package.json +++ b/packages/vant/package.json @@ -46,7 +46,7 @@ "dependencies": { "@vant/icons": "^1.7.1", "@vant/popperjs": "^1.1.0", - "@vant/use": "^1.3.3" + "@vant/use": "^1.3.4" }, "peerDependencies": { "vue": "^3.0.0" diff --git a/packages/vant/src/address-edit/test/__snapshots__/demo.spec.ts.snap b/packages/vant/src/address-edit/test/__snapshots__/demo.spec.ts.snap index aabd05ff7..ed07d9c7a 100644 --- a/packages/vant/src/address-edit/test/__snapshots__/demo.spec.ts.snap +++ b/packages/vant/src/address-edit/test/__snapshots__/demo.spec.ts.snap @@ -6,30 +6,38 @@ exports[`should render demo and match snapshot 1`] = `
-
-
@@ -39,16 +47,20 @@ exports[`should render demo and match snapshot 1`] = ` tabindex="0" >
-
@@ -57,15 +69,19 @@ exports[`should render demo and match snapshot 1`] = `
-
- @@ -74,15 +90,19 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -97,6 +117,7 @@ exports[`should render demo and match snapshot 1`] = `
diff --git a/packages/vant/src/address-edit/test/__snapshots__/index.spec.js.snap b/packages/vant/src/address-edit/test/__snapshots__/index.spec.js.snap index 279729d12..2aaf61dd6 100644 --- a/packages/vant/src/address-edit/test/__snapshots__/index.spec.js.snap +++ b/packages/vant/src/address-edit/test/__snapshots__/index.spec.js.snap @@ -11,30 +11,38 @@ exports[`should render AddressEdit correctly 1`] = `
-
-
@@ -44,16 +52,20 @@ exports[`should render AddressEdit correctly 1`] = ` tabindex="0" >
-
@@ -62,15 +74,19 @@ exports[`should render AddressEdit correctly 1`] = `
-
-
@@ -96,30 +112,38 @@ exports[`should render AddressEdit with props correctly 1`] = `
-
-
@@ -129,16 +153,20 @@ exports[`should render AddressEdit with props correctly 1`] = ` tabindex="0" >
-
@@ -147,15 +175,19 @@ exports[`should render AddressEdit with props correctly 1`] = `
-
-
@@ -163,15 +195,19 @@ exports[`should render AddressEdit with props correctly 1`] = `
-
@@ -186,6 +222,7 @@ exports[`should render AddressEdit with props correctly 1`] = `
@@ -209,15 +246,19 @@ exports[`should render AddressEdit with props correctly 1`] = ` exports[`should valid address detail and render error message correctly 1`] = `
-
- @@ -235,16 +276,20 @@ exports[`should valid area code and render error message correctly 1`] = ` tabindex="0" >
-
@@ -259,15 +304,19 @@ exports[`should valid area code and render error message correctly 1`] = ` exports[`should valid name and render error message correctly 1`] = `
-
@@ -280,15 +329,19 @@ exports[`should valid name and render error message correctly 1`] = ` exports[`should valid postal code and render error message correctly 1`] = `
-
@@ -301,15 +354,19 @@ exports[`should valid postal code and render error message correctly 1`] = ` exports[`should valid tel and render error message correctly 1`] = `
-
diff --git a/packages/vant/src/button/Button.tsx b/packages/vant/src/button/Button.tsx index 1a86daf8f..03a030459 100644 --- a/packages/vant/src/button/Button.tsx +++ b/packages/vant/src/button/Button.tsx @@ -9,6 +9,7 @@ import { import { extend, numericProp, + preventDefault, makeStringProp, createNamespace, BORDER_SURROUND, @@ -135,7 +136,7 @@ export default defineComponent({ const onClick = (event: MouseEvent) => { if (props.loading) { - event.preventDefault(); + preventDefault(event); } else if (!props.disabled) { emit('click', event); route(); diff --git a/packages/vant/src/calendar/CalendarHeader.tsx b/packages/vant/src/calendar/CalendarHeader.tsx index 896b5648b..7cca6aef6 100644 --- a/packages/vant/src/calendar/CalendarHeader.tsx +++ b/packages/vant/src/calendar/CalendarHeader.tsx @@ -26,9 +26,8 @@ export default defineComponent({ } }; - const onClickSubtitle = (event: MouseEvent) => { + const onClickSubtitle = (event: MouseEvent) => emit('click-subtitle', event); - }; const renderSubtitle = () => { if (props.showSubtitle) { diff --git a/packages/vant/src/cascader/Cascader.tsx b/packages/vant/src/cascader/Cascader.tsx index deda430eb..a6578ef69 100644 --- a/packages/vant/src/cascader/Cascader.tsx +++ b/packages/vant/src/cascader/Cascader.tsx @@ -205,8 +205,10 @@ export default defineComponent({ selectedOption: CascaderOption | null, tabIndex: number ) => { - const selected = - selectedOption && option[valueKey] === selectedOption[valueKey]; + const { disabled } = option; + const selected = !!( + selectedOption && option[valueKey] === selectedOption[valueKey] + ); const color = option.color || (selected ? props.activeColor : undefined); const Text = slots.option ? ( @@ -217,14 +219,12 @@ export default defineComponent({ return (
  • onSelect(option, tabIndex)} > {Text} @@ -240,7 +240,7 @@ export default defineComponent({ selectedOption: CascaderOption | null, tabIndex: number ) => ( -
      +