ckeditor / ckeditor5-react

Official CKEditor 5 React component.
https://ckeditor.com/ckeditor-5
Other
420 stars 100 forks source link

Fix inconsistent behavior of `useAsyncValue` and `useCKEditorCloud` hooks on `Vite` and `Next` runtimes. #541

Closed Mati365 closed 4 days ago

Mati365 commented 4 days ago

Suggested merge commit message (convention)

Fix: Behavior of useCKEditorCloud hook is now consistent on Vite and Next runtimes while changing properties. Internal: Fix incorrect typings of useAsyncCallback and useAsyncValue callback arguments types. Tests: Add missing cleanup methods to few tests.


Additional information

It looks like useRef behavior is inconsistent across React frameworks, and it is not related to React version itself (at least 18.x one, 19.x is not affected at all).

Let's assume this component that is being rendered in strict mode:

const Component = () => {
    const ref = useRef(null);

    console.info(ref.current);

    ref.current = 'test';

    return null;
};
  1. On Vite it will print null two times.
  2. On Next.js it will print null the first time, and then test second time.

It looks like something changed somewhere in React world and second approach is no longer consistent across frameworks. At the time of creating useInstantEffect it was. It affects our useCKEditorCloud which uses useInstantEffect under the hood, which may work differently across frameworks above. This PR normalizes it.

filipsobol commented 4 days ago

LGTM, but as I have little knowledge of React, I'd be good if someone else looked at this PR too.

Mati365 commented 4 days ago

Thanks for digging it more @gorzelinski, I'm merging then.