DaniGuardiola / rpc-anywhere

Create a type-safe RPC anywhere.
https://rpc-anywhere.dio.la
MIT License
168 stars 1 forks source link

Bug: iframe transport fails at times #24

Closed mscolnick closed 5 months ago

mscolnick commented 5 months ago

In which versions of the package (and relevant enviroment tools such as Node.js) have you observed the bug?

1.6.0

What steps will reproduce the bug?

I am testing locally on the same origin, using nexjs. Sometimes the frames with connect with createIframeParentTransport and createIframeTransport, but 80% of the time, they do not.

My question is: does the order in which createIframeParentTransport and createIframeTransport run matter?

That seems to be the only race condition in my code.

What behavior did you expect?

I would expect them to connect every time regardless of order.

What actually happened?

It connects about 10% of the time

Workaround

Currently don't have a workaround

Proposed fix

No response

Other remarks

No response

Contribution

mscolnick commented 5 months ago

I think I found the issue:

https://github.com/DaniGuardiola/rpc-anywhere/blob/06d3efb3546bbfb37c181ab42f8f341e3a068718/src/transports/iframe.ts#L93

If the iframe is already loaded, it gets stuck here. Maybe checking iframeDoc.readyState before adding the event listener?

My current workaround is to just force the event with iframe.dispatchEvent(new Event("load"));

DaniGuardiola commented 5 months ago

@mscolnick this should be fixed now. Please upgrade and let me know if your project now works. Btw, can you share information about browser, OS, and the versions of the software you're experiencing this bug in?

DaniGuardiola commented 5 months ago

Fix shipped in v1.7.

mscolnick commented 5 months ago

Thanks! I'll let you know if it does work, but I expect it to be fine.

Chrome 122 MacOS Nextjs 14 React 18

DaniGuardiola commented 5 months ago

@mscolnick mind confirming if the fix worked for you?

mscolnick commented 5 months ago

Yep it did, thanks for the quick fix!