@@ -110,7 +110,15 @@ function applyHmr(args) {
110
110
nonCssHash &&
111
111
existing . current . nonCssHash === nonCssHash
112
112
113
- r . update ( { Component, hotOptions, canAccept, cssId, nonCssHash, cssOnly } )
113
+ r . update ( {
114
+ Component,
115
+ hotOptions,
116
+ canAccept,
117
+ nonCssHash,
118
+ cssId,
119
+ previousCssId : r . current . cssId ,
120
+ cssOnly,
121
+ } )
114
122
115
123
hot . dispose ( data => {
116
124
// handle previous fatal errors
@@ -139,18 +147,20 @@ function applyHmr(args) {
139
147
if ( canAccept ) {
140
148
hot . accept ( async arg => {
141
149
const { bubbled } = arg || { }
142
- const newCssId = r . current . cssId
143
- const cssChanged = newCssId !== cssId
150
+ // NOTE Snowpack registers accept handlers only once, so we can NOT rely
151
+ // on the surrounding scope variables -- they're not the last module!
152
+ const { cssId : newCssId , previousCssId } = r . current
153
+ const cssChanged = newCssId !== previousCssId
144
154
// ensure old style sheet has been removed by now
145
- if ( cssChanged ) removeStylesheet ( cssId )
155
+ if ( cssChanged ) removeStylesheet ( previousCssId )
146
156
// guard: css only change
147
157
if (
148
158
// NOTE bubbled is provided only by rollup-plugin-hot, and we
149
159
// can't safely assume a CSS only change without it... this means we
150
160
// can't support CSS only injection with Nollup or Webpack currently
151
161
bubbled === false && // WARNING check false, not falsy!
152
162
r . current . cssOnly &&
153
- ( ! cssChanged || replaceCss ( cssId , newCssId ) )
163
+ ( ! cssChanged || replaceCss ( previousCssId , newCssId ) )
154
164
) {
155
165
return
156
166
}
0 commit comments