Browse Source

Disable spell check if WebAssembly is not available (#23136)

GitOrigin-RevId: c209540579e0d8ff7f62dc66ff5d850450b18600
Alf Eaton 1 year ago
parent
commit
6ccf61e1f2

+ 3 - 2
services/web/frontend/js/features/editor-left-menu/components/settings/settings-spell-check-language.tsx

@@ -5,6 +5,7 @@ import { useProjectSettingsContext } from '../../context/project-settings-contex
 import SettingsMenuSelect from './settings-menu-select'
 import type { Optgroup } from './settings-menu-select'
 import { useEditorContext } from '@/shared/context/editor-context'
+import { supportsWebAssembly } from '@/utils/wasm'
 
 export default function SettingsSpellCheckLanguage() {
   const { t } = useTranslation()
@@ -30,12 +31,12 @@ export default function SettingsSpellCheckLanguage() {
   return (
     <SettingsMenuSelect
       onChange={setSpellCheckLanguage}
-      value={spellCheckLanguage}
+      value={supportsWebAssembly() ? spellCheckLanguage : ''}
       options={[{ value: '', label: t('off') }]}
       optgroup={optgroup}
       label={t('spell_check')}
       name="spellCheckLanguage"
-      disabled={permissionsLevel === 'readOnly'}
+      disabled={permissionsLevel === 'readOnly' || !supportsWebAssembly()}
     />
   )
 }

+ 2 - 1
services/web/frontend/js/features/source-editor/hooks/use-hunspell.ts

@@ -4,12 +4,13 @@ import { globalIgnoredWords } from '@/features/dictionary/ignored-words'
 import { HunspellManager } from '@/features/source-editor/hunspell/HunspellManager'
 import { debugConsole } from '@/utils/debugging'
 import { learnedWords } from '@/features/source-editor/extensions/spelling/learned-words'
+import { supportsWebAssembly } from '@/utils/wasm'
 
 export const useHunspell = (spellCheckLanguage: string | null) => {
   const [hunspellManager, setHunspellManager] = useState<HunspellManager>()
 
   useEffect(() => {
-    if (spellCheckLanguage) {
+    if (spellCheckLanguage && supportsWebAssembly()) {
       const lang = (getMeta('ol-languages') ?? []).find(
         item => item.code === spellCheckLanguage
       )

+ 1 - 0
services/web/frontend/js/utils/wasm.ts

@@ -0,0 +1 @@
+export const supportsWebAssembly = () => typeof window.WebAssembly === 'object'