-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: better handling of resync and restarts in content layer #12984
Conversation
🦋 Changeset detectedLatest commit: 8452a0d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #12984 will not alter performanceComparing Summary
|
export function createWatcherWrapper(watcher: FSWatcher): WrappedWatcher { | ||
const listeners = new Map<WatchEventName, Set<WatchEventCallback>>(); | ||
|
||
const handler: ProxyHandler<FSWatcher> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't a proxy overkill for this? Could it be an object?
return {
on: (event, callback) => {
if (!listeners.has(event)) {
listeners.set(event, new Set());
}
// Track the listener
listeners.get(event)!.add(callback);
return watcher.on(event, callback)
},
// off, etc
}
Or is it because you want to support all other methods too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a public API, so it would be a breaking change if I changed the type.
Changes
This PR makes a number of changes to the way that file watchers work in dev with the content layer. There have been a few bugs related to the way that dev server restarts are handled, which were due to the way we were handling file watchers.
When the Astro config is edited, it restarts the dev container to ensure the site is using the latest config. This was causing several bugs:
This PR correctly passes in the watcher, but has to handle various implications of this:
Testing
Added new test cases
Docs