From cddbebb3d905041f7bbd4ee2110bc89d386e1621 Mon Sep 17 00:00:00 2001 From: canisminor1990 Date: Sun, 12 Nov 2023 17:58:43 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20"npm=20run=20setup"?= =?UTF-8?q?=20command=20to=20"docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The package.json file has been modified to include the "npm run setup" command in the "docs:build" and "docs:dev" scripts. This change allows for easier setup and documentation building. Add try-catch block to define SpeechRecognition variable in useRecognition.ts A try-catch block has been added to the useRecognition.ts file to define the SpeechRecognition variable. This change improves error handling and ensures the variable is properly defined. --- package.json | 5 ++--- src/useSpeechRecognition/useRecognition.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7d7dfc0..3992c52 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,10 @@ "build:server": "tsc server.ts --declaration", "ci": "npm run lint && npm run type-check", "dev": "father dev", - "docs:build": "dumi build", + "docs:build": "npm run setup && dumi build", "docs:build-analyze": "ANALYZE=1 dumi build", - "docs:dev": "dumi dev", + "docs:dev": "npm run setup && dumi dev", "doctor": "father doctor", - "postinstall": "npm run setup", "lint": "eslint \"{src,api,lib}/**/*.{js,jsx,ts,tsx}\" --fix", "lint:md": "remark . --quiet --frail --output", "prepare": "husky install", diff --git a/src/useSpeechRecognition/useRecognition.ts b/src/useSpeechRecognition/useRecognition.ts index 5fa26dc..abd37f9 100644 --- a/src/useSpeechRecognition/useRecognition.ts +++ b/src/useSpeechRecognition/useRecognition.ts @@ -1,8 +1,11 @@ import { useCallback, useEffect, useState } from 'react'; -const SpeechRecognition = - // @ts-ignore - (globalThis as any)?.SpeechRecognition || (window as any)?.webkitSpeechRecognition; +let SpeechRecognition: any; + +try { + SpeechRecognition = + (globalThis as any)?.SpeechRecognition || (window as any)?.webkitSpeechRecognition; +} catch {} export const useRecognition = ( locale: string,