зеркало из https://github.com/github/remote-form.git
Prevent errors if remoteForm is run in an SSR environment
This commit is contained in:
Родитель
3183c0c05b
Коммит
b37e681f21
|
@ -78,7 +78,10 @@ export function beforeRemote(fn: Handler): void {
|
|||
export function remoteForm(selector: string, fn: RemoteFormHandler): void {
|
||||
if (!formHandlers) {
|
||||
formHandlers = new Map<string, RemoteFormHandler[]>()
|
||||
document.addEventListener('submit', handleSubmit)
|
||||
|
||||
if (typeof document !== 'undefined') {
|
||||
document.addEventListener('submit', handleSubmit)
|
||||
}
|
||||
}
|
||||
const handlers = formHandlers.get(selector) || []
|
||||
formHandlers.set(selector, [...handlers, fn])
|
||||
|
|
Загрузка…
Ссылка в новой задаче