Live reloading Discussion

Bug, discuss, implementation detail, how to improve Live reloading in Plasmo
29 Replies
lab
labOP•2y ago
@pdina So at a high level, Plasmo live-reload works as follow: 1. User change some code 2. Parcel takes the code, creates an incremental diff, and publishes that via the HMR socket 3. Plasmo script runtime (PSR) receives this HMR event and logged a potential change after checking if the diff is related to itself (dependency checking) 4. Parcel rebuild the bundle, producing a new build output into the build directory 5. Plasmo watches the build directory and broadcast another change event via a Builder socket 6. PSR receives the builder event 7. PSR checks if both an HMR was fired AND a builder event was fired -> trigger reload after telling the bgsw to reload the full extension bundle --- So the issues likely happen because there could be many 2 and 5 events being fired that are all related to the initial code change at 1. However, the PSR only check for one of each event, and thus it triggers reload too early, resulting in rendering stale changes Here's the source for PSR: https://github.com/PlasmoHQ/plasmo/blob/main/packages/parcel-runtime/src/runtimes/script-runtime.ts Step 7 happens here: https://github.com/PlasmoHQ/plasmo/blob/main/packages/parcel-runtime/src/runtimes/background-service-runtime.ts#LL21C42-L21C43
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
where should we put them?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
also, assuming we placed the breakpoint and traversed through the debug run and see that there's indeed a race condition between these systems or maybe it might be something entirely diff, I wonder how would these type of race condition usually solved?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
good point, let me see if we can find the race cond hmmm Something tells me this is an issue: https://github.com/parcel-bundler/watcher/releases/tag/v2.0.6
Update debounce to emit the first update immediately, and always emit at least one event every 500ms – #113
If this is the case the events emitted might not contain any change at all (?)...
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
afaik, this issue has been around since forever - we tried different method and iterate on the solution but thus far have yet to fix it xd @pdina can you try running your extension with the --verbose flag also, make sure you're on latest version
lab
labOP•2y ago
lab
labOP•2y ago
So indeed, I am receiving 3 build trigger for 1 code change
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
yeah, use the code tag! (or if it's too long we can pastebin/gist it :p)
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
What is the log after you make a change to one of the plasmo-overlay file?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
awesome, and can you paste the log on the browser as well
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
yup - inspector/console content script logs are printed in the webpage's console itself
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
ooh and can you toggle preserve log:
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Arcane
Arcane•2y ago
@pdina has reached level 3. GG!
lab
labOP•2y ago
Also ignore the minified react error - that's actually from out website xd.....
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
@pdina try it out by swapping the plasmo version in package.json with canary
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
lab
labOP•2y ago
I'm tempted to rename the canary tag to lab :d.... but canary is more commonly used by chromium xD
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server