Solution: ORPC Contract JSON causes page reload with Vite HMR #744
hunterwilhelm
started this conversation in
General
Replies: 1 comment 1 reply
-
And your |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I already found a solution to this but wanted to share what I did to solve it.
The problem: Vite's HMR system can't update because they are static objects at the top of the dependency tree.
The solution: Tell vite it's safe to Update instead of Page Reload and handle the update ourselves.
Step 1: import your contract json as normal
Step 2: Update the contract using a reactive signal library. E.g. Vue's
ref()
And then update the value of the ref as contract changes.
Step 3: Rebuild the orpc client when it changes
Step 4: For convenience make a proxy object that accesses whatever the current value of the signal (ref) is.
You can customize with your reactivity library.
Step 6: Feel free to use it as normal, no page reloads, only updates 🥳
Beta Was this translation helpful? Give feedback.
All reactions