mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Update Vite ws property to hot (#10138)
This commit is contained in:
parent
5ff288f61b
commit
41a6baa080
6 changed files with 19 additions and 19 deletions
|
@ -172,7 +172,7 @@ export async function createContentTypesGenerator({
|
|||
}
|
||||
const collectionInfo = collectionEntryMap[collectionKey];
|
||||
if (collectionInfo.type === 'content') {
|
||||
viteServer.ws.send({
|
||||
viteServer.hot.send({
|
||||
type: 'error',
|
||||
err: new AstroError({
|
||||
...AstroErrorData.MixedContentDataCollectionError,
|
||||
|
@ -212,7 +212,7 @@ export async function createContentTypesGenerator({
|
|||
}
|
||||
const collectionInfo = collectionEntryMap[collectionKey];
|
||||
if (collectionInfo.type === 'data') {
|
||||
viteServer.ws.send({
|
||||
viteServer.hot.send({
|
||||
type: 'error',
|
||||
err: new AstroError({
|
||||
...AstroErrorData.MixedContentDataCollectionError,
|
||||
|
@ -359,7 +359,7 @@ async function writeContentFiles({
|
|||
typeTemplateContent: string;
|
||||
contentEntryTypes: Pick<ContentEntryType, 'contentModuleTypes'>[];
|
||||
contentConfig?: ContentConfig;
|
||||
viteServer: Pick<ViteDevServer, 'ws'>;
|
||||
viteServer: Pick<ViteDevServer, 'hot'>;
|
||||
}) {
|
||||
let contentTypesStr = '';
|
||||
let dataTypesStr = '';
|
||||
|
@ -374,7 +374,7 @@ async function writeContentFiles({
|
|||
collection.type !== 'unknown' &&
|
||||
collection.type !== collectionConfig.type
|
||||
) {
|
||||
viteServer.ws.send({
|
||||
viteServer.hot.send({
|
||||
type: 'error',
|
||||
err: new AstroError({
|
||||
...AstroErrorData.ContentCollectionTypeMismatchError,
|
||||
|
@ -387,7 +387,7 @@ async function writeContentFiles({
|
|||
collection.type === 'data'
|
||||
? "Try adding `type: 'data'` to your collection config."
|
||||
: undefined,
|
||||
location: { file: '' /** required for error overlay `ws` messages */ },
|
||||
location: { file: '' /** required for error overlay `hot` messages */ },
|
||||
}) as any,
|
||||
});
|
||||
return;
|
||||
|
|
|
@ -80,7 +80,7 @@ export async function restartContainer(container: Container): Promise<Container
|
|||
);
|
||||
}
|
||||
// Inform connected clients of the config error
|
||||
container.viteServer.ws.send({
|
||||
container.viteServer.hot.send({
|
||||
type: 'error',
|
||||
err: {
|
||||
message: error.message,
|
||||
|
|
|
@ -31,8 +31,8 @@ export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader {
|
|||
}
|
||||
});
|
||||
|
||||
const _wsSend = viteServer.ws.send;
|
||||
viteServer.ws.send = function (...args: any) {
|
||||
const _wsSend = viteServer.hot.send;
|
||||
viteServer.hot.send = function (...args: any) {
|
||||
// If the tsconfig changed, Vite will trigger a reload as it invalidates the module.
|
||||
// However in Astro, the whole server is restarted when the tsconfig changes. If we
|
||||
// do a restart and reload at the same time, the browser will refetch and the server
|
||||
|
@ -75,13 +75,13 @@ export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader {
|
|||
return viteServer.ssrFixStacktrace(err);
|
||||
},
|
||||
clientReload() {
|
||||
viteServer.ws.send({
|
||||
viteServer.hot.send({
|
||||
type: 'full-reload',
|
||||
path: '*',
|
||||
});
|
||||
},
|
||||
webSocketSend(msg) {
|
||||
return viteServer.ws.send(msg);
|
||||
return viteServer.hot.send(msg);
|
||||
},
|
||||
isHttps() {
|
||||
return !!viteServer.config.server.https;
|
||||
|
|
|
@ -101,14 +101,14 @@ export async function syncInternal(
|
|||
)
|
||||
);
|
||||
|
||||
// Patch `ws.send` to bubble up error events
|
||||
// `ws.on('error')` does not fire for some reason
|
||||
const wsSend = tempViteServer.ws.send;
|
||||
tempViteServer.ws.send = (payload: HMRPayload) => {
|
||||
// Patch `hot.send` to bubble up error events
|
||||
// `hot.on('error')` does not fire for some reason
|
||||
const hotSend = tempViteServer.hot.send;
|
||||
tempViteServer.hot.send = (payload: HMRPayload) => {
|
||||
if (payload.type === 'error') {
|
||||
throw payload.err;
|
||||
}
|
||||
return wsSend(payload);
|
||||
return hotSend(payload);
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
|
@ -54,7 +54,7 @@ export async function handleHotUpdate(
|
|||
ctx.server.moduleGraph.invalidateModule(mod);
|
||||
}
|
||||
}
|
||||
ctx.server.ws.send({ type: 'full-reload', path: '*' });
|
||||
ctx.server.hot.send({ type: 'full-reload', path: '*' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,21 +25,21 @@ export default function astroDevToolbar({ settings, logger }: AstroPluginOptions
|
|||
}
|
||||
},
|
||||
configureServer(server) {
|
||||
server.ws.on('astro:devtoolbar:error:load', (args) => {
|
||||
server.hot.on('astro:devtoolbar:error:load', (args) => {
|
||||
logger.error(
|
||||
'toolbar',
|
||||
`Failed to load dev toolbar app from ${args.entrypoint}: ${args.error}`
|
||||
);
|
||||
});
|
||||
|
||||
server.ws.on('astro:devtoolbar:error:init', (args) => {
|
||||
server.hot.on('astro:devtoolbar:error:init', (args) => {
|
||||
logger.error(
|
||||
'toolbar',
|
||||
`Failed to initialize dev toolbar app ${args.app.name} (${args.app.id}):\n${args.error}`
|
||||
);
|
||||
});
|
||||
|
||||
server.ws.on('astro:devtoolbar:app:toggled', (args) => {
|
||||
server.hot.on('astro:devtoolbar:app:toggled', (args) => {
|
||||
// Debounce telemetry to avoid recording events when the user is rapidly toggling apps for debugging
|
||||
clearTimeout(telemetryTimeout);
|
||||
telemetryTimeout = setTimeout(() => {
|
||||
|
|
Loading…
Reference in a new issue