holochain / holochain-client-js

A JavaScript client for the Holochain Conductor API
Other
258 stars 15 forks source link

Add workaround for cell_id being a proxy object in Vue #227

Closed matthme closed 9 months ago

matthme commented 9 months ago

Adds a workaround for the case where the AppAgentClient is used as a proxy object in Vue and therefore the cell_id is passed as a proxy object to callZome instead of a normal javascript array.

matthme commented 9 months ago

It's maybe debatable whether the workaround for this should be placed in the js-client but it seems like a negligible change to add it in that place and makes life easier for implementors of host zome call signers because it's quite unexpected to get a proxy object in the zome call request.

jost-s commented 9 months ago

I'm fine with merging that, sure. Can you show an example in Vue where that falls over?

matthme commented 9 months ago

Yes - you can run the hc scaffold example forum (the holochain 0.1 version of it) with Vue as framework and then you will see that zome calls throw the error Error: An object could not be cloned.. This is electron that's complaining because it can't serialize the cell_id since it's not an actual javascript object but a Vue proxy object. The latter you can see if you log the cell_id here in the js-client.

jost-s commented 9 months ago

I can not confirm that. I just created a new forum app with Vue, ran npm install and start and it works fine

image

It would be surprising if this hasn't been working all along. Can you doublecheck if this happens for you on a freshly scaffolded project?

matthme commented 9 months ago

Oh sorry, my instructions were not correct. I forgot that I ran it with the scaffolding from this PR. So you'd need to use hc-spin to start the app instead of hc-launch since in the hc-launch case the js-client does some conversions of the zome call request object before sending it over IPC to the tauri backend.

matthme commented 9 months ago

Or in your existing project: npm install --save-dev @holochain/hc-spin@">=0.100.0 <0.200.0" and then modify the launch:happ script to:

    "launch:happ": "hc-spin -n $AGENTS --ui-port $UI_PORT workdir/forum.happ",
jost-s commented 9 months ago

released as v0.12.8