Live reloading Discussion
Bug, discuss, implementation detail, how to improve Live reloading in Plasmo
29 Replies
@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-L21C43Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
where should we put them?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
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•2y ago
Message Not Public
Sign In & Join Server To View
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 – #113If this is the case the events emitted might not contain any change at all (?)...
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
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 versionSo indeed, I am receiving 3 build trigger for 1 code change
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yeah, use the code tag!
(or if it's too long we can pastebin/gist it :p)
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
What is the log after you make a change to one of the plasmo-overlay file?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
awesome, and can you paste the log on the browser as well
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yup - inspector/console
content script logs are printed in the webpage's console itself
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ooh and can you toggle preserve log:
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@pdina has reached level 3. GG!
Also ignore the minified react error - that's actually from out website xd.....
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@pdina try it out by swapping the plasmo version in package.json with
canary
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I'm tempted to rename the canary tag to
lab
:d....
but canary is more commonly used by chromium xDUnknown User•2y ago
Message Not Public
Sign In & Join Server To View