web worker not responding instantly

I have a next js project and in that i have this fn that i run on, onKeyDownCapture
NOTE- the Fn works fine when its being executed on the main thread in the same file but when i move it to the web worker that is when the problem arises.

the worker and the main thread are successfully connected and send messages to and fro, have verified this

Now as we know the communication of the main thread with the worker is asynchronous, so i guess that might be causing the problem, that even though the worker returns true when the computation is done because its async we’re kinda not being able to see its effect on the main thread

THE FN normally on the main thread (just for simplified context)

  const handleBackspace1 = useCallback(
    throttle((event, editor) => {
      if (event.key === 'Backspace') {
        const cursorPosition = editor.getTextCursorPosition();

        if (
          (cursorPosition.block.type === "paragraph" && cursorPosition.block.content.length === 0) &&
          customComponentsRef.current.includes(cursorPosition?.prevBlock?.type)
        ) {
          editor.setTextCursorPosition(cursorPosition.prevBlock, "end");
          event.preventDefault();
          event.stopPropagation();
          return false;
        } else {
          return true;
        }
      }
    }, 150), 
    []
  );

the actual web worker implementation part ->

  useEffect(() => {
    if (router.isReady) {

      workerRef.current = new Worker(new URL('../../../../Workers/BackspaceWorkerForEditor.js', import.meta.url));

      return () => {
        workerRef.current.terminate();
      };
    }
  }, []);

FN WITH THE WEB WORKER

  const handleBackspace = (event) => {
    console.log('1');
    if (event.key === 'Backspace' && typeof window !== 'undefined' && router.isReady) {
      console.log('2');
      const cursorPosition = editor.getTextCursorPosition();

      if (workerRef.current) {
        workerRef.current.postMessage({
          cursorPosition,
          customComponents: customComponentsRef.current,
        });

        workerRef.current.onmessage = function (e) {
          const { shouldPreventDefault, prevBlock } = e.data;
          console.log(shouldPreventDefault);

          if (shouldPreventDefault) {
            console.log('prevent default', shouldPreventDefault);
            editor.setTextCursorPosition(prevBlock, "end");
            event.preventDefault();
          }
        };
      }
    }
  };

the woker script

function handleMessage(event) {
  const { cursorPosition, customComponents } = event.data;
  if (
    cursorPosition.block.type === "paragraph" &&
    cursorPosition.block.content.length === 0 &&
    customComponents.includes(cursorPosition.prevBlock?.type)
  ) {
    postMessage({ shouldPreventDefault: true, prevBlock: cursorPosition.prevBlock });
  } else {
    postMessage({ shouldPreventDefault: false });
  }
}

self.addEventListener('message', handleMessage);

sample logs showing that yes the worker and the main thread is connected and inspite of the worker returning true we’re not able to prevent default/stop propogation

2
Editor.jsx:189 true
Editor.jsx:192 prevent default true

Can somebody please help me with it

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật