(context)
| 147 | } |
| 148 | }, |
| 149 | async handleHotUpdate(context) { |
| 150 | const toReturnModules: ModuleNode[] = []; |
| 151 | for (let module of context.modules) { |
| 152 | const fileId = path.normalize(module.file); |
| 153 | const fileBasename = path.basename(fileId); |
| 154 | |
| 155 | if (page.pageCtx.filePath === fileId) { |
| 156 | /** |
| 157 | * If the pageCtx is equal to the fileId then check if the components have changed, |
| 158 | * If the components have not changed then just re request the page and update it using million.js |
| 159 | * Else reload the entire page to remove the previous module from the HMR system |
| 160 | */ |
| 161 | const [, meta] = await compile( |
| 162 | await fs.readFile(page.pageCtx.filePath, { encoding: "utf-8" }) |
| 163 | ); |
| 164 | const newHash = hashIt({ |
| 165 | components: meta.components, |
| 166 | head: meta.head, |
| 167 | }); |
| 168 | if (newHash !== page.prevHash) { |
| 169 | reload(fileBasename, context.server, utils.logger); |
| 170 | seen = []; |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | utils.logger.info(`Page reload ${fileBasename}`, { |
| 175 | timestamp: true, |
| 176 | clear: true, |
| 177 | }); |
| 178 | |
| 179 | context.server.ws.send({ |
| 180 | type: "custom", |
| 181 | event: "new:page", |
| 182 | }); |
| 183 | return; |
| 184 | } else if (page.reloads.includes(fileId)) { |
| 185 | /** |
| 186 | * Reload the page. (mainly for handling the loader and layout files) |
| 187 | */ |
| 188 | if (/\.[tj]sx?$/.test(fileId)) { |
| 189 | // time to throw away the fileToURL cache entry for this thing and re-import this file. |
| 190 | purgeLoaderCache(fileId); |
| 191 | } |
| 192 | reload(fileBasename, context.server, utils.logger); |
| 193 | seen = []; |
| 194 | return; |
| 195 | } else { |
| 196 | toReturnModules.push(module); |
| 197 | } |
| 198 | } |
| 199 | return toReturnModules; |
| 200 | }, |
| 201 | }; |
| 202 | } |
nothing calls this directly
no test coverage detected