Skip to content

Commit 71d5423

Browse files
committed
refactor: handleHotUpdate will be removed, use hotUpdate instead
1 parent fd277a2 commit 71d5423

5 files changed

Lines changed: 45 additions & 36 deletions

File tree

.claude/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "0.0.1",
3+
"configurations": [
4+
{
5+
"name": "blog",
6+
"runtimeExecutable": "pnpm",
7+
"runtimeArgs": ["blog"],
8+
"port": 5173
9+
}
10+
]
11+
}

.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"mcp__Claude_Preview__preview_start"
5+
]
6+
}
7+
}

packages/iles/src/node/plugin/plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ export default function IslandsPlugins (appConfig: AppConfig): PluginOption[] {
116116
if (id === APP_COMPONENT_PATH && !isBuild && appConfig.debug)
117117
return code.replace('const DebugPanel = () => null', () => `import DebugPanel from '${DEBUG_COMPONENT_PATH}'`)
118118
},
119-
handleHotUpdate ({ file, server }) {
120-
if (file === appPath) return [server.moduleGraph.getModuleById(USER_APP_REQUEST_PATH)!]
121-
if (file === sitePath) return [server.moduleGraph.getModuleById(USER_SITE_REQUEST_PATH)!]
119+
hotUpdate ({ file }) {
120+
if (file === appPath) return [this.environment.moduleGraph.getModuleById(USER_APP_REQUEST_PATH)!]
121+
if (file === sitePath) return [this.environment.moduleGraph.getModuleById(USER_SITE_REQUEST_PATH)!]
122122
},
123123
configureServer (devServer) {
124124
server = devServer

packages/pages/src/hmr.ts

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,42 @@
11
import type { ViteDevServer, Plugin } from 'vite'
22
import { debug, slash } from './utils'
3-
import { Awaitable, MODULE_ID, ResolvedOptions, PagesApi } from './types'
3+
import { MODULE_ID, ResolvedOptions, PagesApi } from './types'
44

5-
export function handleHMR (api: PagesApi, options: ResolvedOptions, clearRoutes: () => void): Plugin['handleHotUpdate'] {
5+
export function handleHMR (api: PagesApi, options: ResolvedOptions, clearRoutes: () => void): Plugin['hotUpdate'] {
66
const server = options.server!
77

8-
onPage('add', async (path) => {
9-
const page = await api.addPage(path)
10-
debug.hmr('add %s %O', path, page)
11-
return true
12-
})
13-
14-
onPage('unlink', (path) => {
15-
api.removePage(path)
16-
debug.hmr('remove', path)
17-
return true
18-
})
19-
20-
return async (ctx) => {
21-
const path = slash(ctx.file)
8+
return async function ({ file, type }) {
9+
const path = slash(file)
2210
if (api.isPage(path)) {
23-
const { changed, needsReload } = await api.updatePage(path)
24-
if (changed) debug.hmr('change', path)
25-
if (needsReload) fullReload()
11+
switch (type) {
12+
case 'create': {
13+
const page = await api.addPage(path)
14+
debug.hmr('add %s %O', path, page)
15+
fullReload()
16+
return []
17+
}
18+
case 'delete': {
19+
api.removePage(path)
20+
debug.hmr('remove', path)
21+
fullReload()
22+
return []
23+
}
24+
case 'update': {
25+
const { changed, needsReload } = await api.updatePage(path)
26+
if (changed) debug.hmr('change', path)
27+
if (needsReload) fullReload()
28+
}
29+
}
2630
}
2731
}
2832

29-
function onPage (eventName: string, handler: (path: string) => Awaitable<void | boolean>) {
30-
server.watcher.on(eventName, async (path) => {
31-
path = slash(path)
32-
if (api.isPage(path) && await handler(path))
33-
fullReload()
34-
})
35-
}
36-
3733
function fullReload () {
3834
invalidatePagesModule(server)
3935
clearRoutes()
4036
server.ws.send({ type: 'full-reload' })
4137
}
4238
}
4339

44-
function invalidatePageFiles (path: string, { moduleGraph }: ViteDevServer) {
45-
moduleGraph.getModulesByFile(path)
46-
?.forEach(mod => moduleGraph.invalidateModule(mod))
47-
}
48-
4940
function invalidatePagesModule ({ moduleGraph }: ViteDevServer) {
5041
const mod = moduleGraph.getModuleById(MODULE_ID)
5142
if (mod) moduleGraph.invalidateModule(mod)

packages/pages/src/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function IlesPages (): any {
5858
},
5959
async configureServer (server) {
6060
options.server = server
61-
plugin.handleHotUpdate = handleHMR(api, options, () => { generatedRoutes = undefined })
61+
plugin.hotUpdate = handleHMR(api, options, () => { generatedRoutes = undefined })
6262
},
6363
async buildStart () {
6464
await api.addAllPages()

0 commit comments

Comments
 (0)