NEARBuilders / near-bos-webcomponent

Embed NEAR BOS content as a web component
https://petersalomonsen.github.io/near-bos-webcomponent/devhub.near/widget/app
The Unlicense
12 stars 6 forks source link

Support hot reload #20

Open elliotBraem opened 3 weeks ago

elliotBraem commented 3 weeks ago

In order to be able to fully replace the bos-workspace default gateway with near-bos-webcomponent, we need to introduce hot reloading.

Pull over the useRedirectHook from bos-workspace/gateway. This can also do some code clean-up in App.js -> Viewer, although maintain the "nearSocialVMredirectMap" SESSION_STORAGE_REDIRECT_MAP_KEY

Include documentation on how to use redirect map with hot reload (web socket) or session storage

petersalomonsen commented 2 weeks ago

Remember that "Don't ask again" ( https://github.com/NEARBuilders/bos-workspace/issues/114 ) does not work with the redirect map. I believe that rather than using a redirectmap, a local RPC proxy should be provided that intercepts the calls that the VM does to get widget content, replacing the result with local widget content.

Maybe we should solve that part in bos-workspace first? So that it is possible to use "Don't ask again"?

elliotBraem commented 2 weeks ago

I just investigated #114 and found the issue: it was misuse of the "commander" package for the cli. I've opened a pull request here to fix it. With this change, I have confirmed that disabling hot reload (bw dev --no-hot) will not use redirectMap in bos-workspace gateway, and will only use the rpc proxy that bos-workspace provides, see below:

image

image


Now regarding redirectmap, maybe we should discuss more for clarity:

In the pull request #26, the "useRedirectMap" hook handles three scenarios:

  1. local storage "flags" holding bosLoaderUrl (backwards compatibility with bos-loader)
  2. session storage redirect map key (support devhub test solution)
  3. hot reload enabled by "enablehotreload" attribute on the web component, gets url from environment or hardcoded (meh)

I agree that rpc proxy is much better and replaces the need for 1 + 2 -- and if we had to keep supporting one of these two, I would only keep session storage, because using bosLoaderUrl can be unpredictable (e.g. what port is it running on?). Although if we don't need to support either, that'd be nice too!

My hope is to replace bos-workspace gateway with near-bos-webcomponent, and adding support for hot reload and ether.js are the only two items missing. And as shown in the fix, I think with hotreloadenabled = false, we can circumvent the redirectMap altogether and it will only use RPC proxy, satisfying the need when running a gateway for tests.