@@ -11,13 +11,16 @@ import RefreshIcon from '@mui/icons-material/Refresh';
11
11
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff' ;
12
12
import VisibilityIcon from '@mui/icons-material/Visibility' ;
13
13
import Tooltip from '@mui/material/Tooltip' ;
14
+ import { createWorkerFactory , useWorker } from '@shopify/react-web-worker' ;
14
15
import { MainContext } from '../../contexts/MainContextProvider' ;
15
16
import PasswordStrength from '../../utils/PasswordStrength' ;
16
17
import LinearProgressWithLabel from '../LinearProgressWithLabel' ;
17
18
import { setError } from '../../reducers/MainReducer/Actions' ;
18
19
import { generatePasswordArray , getFullCharacterSet } from '../../reducers/PasswordReducer/Actions' ;
19
20
import { PasswordContext } from '../../contexts/PasswordContextProvider' ;
20
21
22
+ const createWorker = createWorkerFactory ( ( ) => import ( '../../utils/PasswordGenerator/index' ) ) ;
23
+
21
24
const CreatePasswordDialog = ( { open, onCreate, onClose } ) => {
22
25
const [ state , d1 ] = useContext ( MainContext ) ;
23
26
const [ state2 ] = useContext ( PasswordContext ) ;
@@ -55,6 +58,8 @@ const CreatePasswordDialog = ({ open, onCreate, onClose }) => {
55
58
brackets ,
56
59
) ;
57
60
61
+ const worker = useWorker ( createWorker ) ;
62
+
58
63
const cannotGenerate = ! simpleCharacterSet || simpleCharacterSet . length === 0
59
64
|| min > max || max < min ;
60
65
@@ -100,7 +105,7 @@ const CreatePasswordDialog = ({ open, onCreate, onClose }) => {
100
105
return ;
101
106
}
102
107
103
- generatePasswordArray ( min , max , simpleCharacterSet , 1 , allowDuplicates , null )
108
+ generatePasswordArray ( min , max , simpleCharacterSet , 1 , allowDuplicates , worker )
104
109
. then ( ( res ) => {
105
110
setPassword ( res [ 0 ] ) ;
106
111
} )
0 commit comments