Skip to content
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

Dispatch custom event when editor is ready #1134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ivarnakken
Copy link
Member

I believe this will be useful for our e2e spec, but I haven't tested it in practice because I can't get the local package linking to work ..

@ivarnakken ivarnakken added review-needed Pull requests that need review small-fix Pull requests that fix something small labels Mar 24, 2024
@ivarnakken ivarnakken self-assigned this Mar 24, 2024
@eikhr
Copy link
Member

eikhr commented Mar 25, 2024

I agree, it should be possible to actually wait for the editor to be ready with this:)

Comment on lines +262 to +266
useEffect(() => {
const event = new CustomEvent('editorReady');
window.dispatchEvent(event);
}, []);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually on second thought I'm not sure. I think maybe the Slate-component needs some time to initialize, and this wouldn't take that into account

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it'll work 100% either, but we might as well test it out and see how it works :shipit: tried researching for other options but can't seem to find many better alternatives

Copy link
Member

@eikhr eikhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this doesn't work. I tested it a bit locally (by using yarn pack to get a tar.gz archive of the new version and then installing it using "file:<filename>" in package.json of lego-webapp). Even when I was finally able to make cypress wait for the "editorReady"-event, it still fails about 1/3 of the times when the first action is typing into the editor.

@ivarnakken
Copy link
Member Author

@eikhr I only get errors when I do exactly what you do for testing ...

However, do you think it would help if we added value as a dependency to the useEffect?

@eikhr
Copy link
Member

eikhr commented Apr 29, 2024

I don't think so. The event emitter works fine and we get one event when the component is initially rendered, but it seems Slate is still not ready to accept input at this time. I think there is something internally in Slate that runs async and must be finished before it starts accepting inputs. I'm not really sure how we can detect that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-needed Pull requests that need review small-fix Pull requests that fix something small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants