-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot Paste Into Block Content in Mozilla #6715
Comments
Same issue here—it appears to be a Firefox-specific compatibility issue. When I switch to Chrome I can paste as normal. Looking in the debugger, I see this in a comment above the error message:
|
Same issue here, we are using sanity 3.43.0 with Node 18. It works fine with Chrome and Safari. |
Weirdly this warning is logged in Chrome as well, but there content is pasted. From the source it seems like this is all called from here, but the majority of this function deals with pasted files, which are ignored. It's the last line, |
Turns out the But I found the problem, it is here. When debugging this function it turns out that Testing a bit and it seems like both Chrome and Firefox clear the clipboardData after awaiting a short timeout, but Chrome does not clear it when the promise resolves right await: bucket.addEventListener('paste', async e => {
bucket.textContent = 'Pasted!\n';
new Promise(r => r()).then(r => {
writeln(`Promised ${e.clipboardData.items.length}`); // this outputs 0 in Firefox but 2 in Chrome
})
new Promise(r => setTimeout(r, 1)).then(() => {
writeln(`Timeout ${e.clipboardData.items.length}`); // this outputs 0 in both Firefox and Chrome
})
}, false); You can try it out in both Chrome and Firefox here: https://codepen.io/mariusgundersen/full/dyEvbdj |
Can confirm same issue with |
I've been trying to fix this. The problem is that
So the promise chain here isn't awaited, which means it runs in parallel with the promise chain in the other function, which only depends on This can be fixed if the code in const handlePaste = useCallback(
(event: ClipboardEvent<HTMLDivElement>): Promise<void> | void => {
event.preventDefault()
if (!slateEditor.selection) {
return
}
if (!onPaste) {
debug('Pasting normally')
slateEditor.insertData(event.clipboardData)
return
}
try{
const value = PortableTextEditor.getValue(portableTextEditor)
const ptRange = toPortableTextRange(value, slateEditor.selection, schemaTypes)
const path = ptRange?.focus.path || []
const result = onPaste({
event,
value,
path,
schemaTypes,
})
change$.next({type: 'loading', isLoading: true})
if(!result){
debug('No result from custom paste handler, pasting normally')
slateEditor.insertData(event.clipboardData)
return
} else {
Promise.resolve(result)
.then((result) => {
debug('Custom paste function from client resolved', result)
change$.next({type: 'loading', isLoading: true})
if (!result || !result.insert) {
debug('No result from custom paste handler, pasting normally')
slateEditor.insertData(event.clipboardData)
return
}
if (result && result.insert) {
slateEditor.insertFragment(
toSlateValue(result.insert as PortableTextBlock[], {schemaTypes}),
)
change$.next({type: 'loading', isLoading: false})
return
}
console.warn('Your onPaste function returned something unexpected:', result)
})
.catch((error) => {
change$.next({type: 'loading', isLoading: false})
console.error(error) // eslint-disable-line no-console
})
}
}catch(error){
change$.next({type: 'loading', isLoading: false})
console.error(error) // eslint-disable-line no-console
}
},
[change$, onPaste, portableTextEditor, schemaTypes, slateEditor],
) |
Attempting to paste any text into a block content field does not work. Nothing happens, and the console displays the following message:
DataTransfer with kind="string" is currently not supported
Pasting anywhere else, for example into a simple string field, still works as expected.
This has been tested on both Windows and MacOS, with npm and bun, both locally and deployed to sanity.io and using Firefox on both systems. Therefore I would assume that it is a bug within the studio, maybe in combination with Firefox.
The text was updated successfully, but these errors were encountered: