Bug 1500979 Comment 1 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

One way to approach this is to add a listener in the [Changes actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/changes.js#31) for the ["stylesheet-added" event fired by the target actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/targets/browsing-context.js#1454).
 
In the handler, we check the [StyleSheetActor's href  ](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/stylesheets.js#256) against any of the source hrefs already collected in the [`this.changes` array in the Changes actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/changes.js#34). 
If there's a match, it means one of the stylesheets we've previously collected changes for has been reloaded (perhaps by a hot reloading script). We should then fire an event from the Changes actor to notify the client, [devtools/client/inspector/changes/ChangesView.js](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/client/inspector/changes/ChangesView.js). 

On the client we can [listen to this new event](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/client/inspector/changes/ChangesView.js#93) and show a warning that the collected changes may no longer be accurate due to the stylesheet reload and prompt the user to copy their changes before continuing (at their own risk) or refreshing the page.
For hot-reloading, one way to approach this is to add a listener in the [Changes actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/changes.js#31) for the ["stylesheet-added" event fired by the target actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/targets/browsing-context.js#1454).
 
In the handler, we check the [StyleSheetActor's href  ](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/stylesheets.js#256) against any of the source hrefs already collected in the [`this.changes` array in the Changes actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/changes.js#34). 
If there's a match, it means one of the stylesheets we've previously collected changes for has been reloaded (perhaps by a hot reloading script). We should then fire an event from the Changes actor to notify the client, [devtools/client/inspector/changes/ChangesView.js](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/client/inspector/changes/ChangesView.js). 

On the client we can [listen to this new event](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/client/inspector/changes/ChangesView.js#93) and show a warning that the collected changes may no longer be accurate due to the stylesheet reload and prompt the user to copy their changes before continuing (at their own risk) or refreshing the page.

For covering the Style Editor use case (the whole stylesheet content gets replaced when the user edits), we need to react to the ["styles-applied" event on the StyleSheetActor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/stylesheets.js#520) when the `kind` argument is `UPDATE_GENERAL`.
For hot-reloading, one way to approach this is to add a listener in the [Changes actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/changes.js#31) for the ["stylesheet-added" event fired by the target actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/targets/browsing-context.js#1454).
 
In the handler, we check the [StyleSheetActor's href  ](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/stylesheets.js#256) against any of the source hrefs already collected in the [`this.changes` array in the Changes actor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/changes.js#34). 
If there's a match, it means one of the stylesheets we've previously collected changes for has been reloaded (perhaps by a hot reloading script). We should then fire an event from the Changes actor to notify the client, [devtools/client/inspector/changes/ChangesView.js](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/client/inspector/changes/ChangesView.js). 

On the client we can [listen to this new event](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/client/inspector/changes/ChangesView.js#93) and show a warning that the collected changes may no longer be accurate due to the stylesheet reload and prompt the user to copy their changes before continuing (at their own risk) or refreshing the page.

For covering the Style Editor use case (the whole stylesheet content gets replaced when the user edits), we need to react to the ["style-applied" event on the StyleSheetActor](https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/devtools/server/actors/stylesheets.js#520) when the `kind` argument is `UPDATE_GENERAL`.

Back to Bug 1500979 Comment 1