Skip to content

Commit

Permalink
fix(core): improve initial custom route detection when using __route
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Feb 7, 2022
1 parent 679d500 commit 934c18c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/node/app/create/resolvePages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ServerPage,
stripImportQuotesFromJson,
} from '../../../shared';
import { fs, globby, readRecentlyChangedFile } from '../../utils/fs';
import { globby, readRecentlyChangedFile } from '../../utils/fs';
import { logger } from '../../utils/logger';
import { path } from '../../utils/path';
import type { App } from '../App';
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function filePathToRoute(
app: App,
filePath: string,
): Promise<string> {
const fileContent = (await fs.readFile(filePath)).toString();
const fileContent = (await readRecentlyChangedFile(filePath)).toString();
const fileExt = path.extname(filePath);

let configuredRoute;
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/node/app/vite/dev/corePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,19 @@ function startWatchingPages(app: App, server: ViteDevServer) {
.on(
'change',
debounce(async (filePath) => {
await resolvePendingChanges?.();

await resolvePages(app, 'add', [
resolveRelativePath(app.dirs.root.path, filePath),
]);

const newRoutes = JSON.stringify(app.pages.map((page) => page.route));

if (newRoutes !== prevRoutes) {
server.ws.send({ type: 'full-reload' });
server.watcher.emit('change', virtualModuleRequestPath.pages);
setTimeout(() => {
server.ws.send({ type: 'full-reload' });
}, 100);
}

prevRoutes = newRoutes;
Expand Down

0 comments on commit 934c18c

Please sign in to comment.