-
Notifications
You must be signed in to change notification settings - Fork 52
perf: resolve decofile state/revision synchronously when already resolved #1089
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,26 +225,46 @@ export const fromEndpoint = (endpoint: string): DecofileProvider => { | |
| return r; | ||
| }, | ||
| ); | ||
|
|
||
| let resolvedProvider: DecofileProvider | null = null; | ||
| decofileProviderPromise.then((r) => { | ||
| resolvedProvider = r; | ||
| }); | ||
|
|
||
| return { | ||
| set(state, revision) { | ||
| if (resolvedProvider) return resolvedProvider.set?.(state, revision) ?? Promise.resolve(); | ||
| return decofileProviderPromise.then((r) => r?.set?.(state, revision)); | ||
| }, | ||
| notify() { | ||
| if (resolvedProvider) return resolvedProvider.notify?.() ?? Promise.resolve(); | ||
| return decofileProviderPromise.then((r) => | ||
| r?.notify?.() ?? Promise.resolve() | ||
| ); | ||
| }, | ||
| state: (options) => decofileProviderPromise.then((r) => r.state(options)), | ||
| state: (options) => { | ||
| if (resolvedProvider) return resolvedProvider.state(options); | ||
| return decofileProviderPromise.then((r) => r.state(options)); | ||
| }, | ||
| onChange: (cb) => { | ||
| if (resolvedProvider) return resolvedProvider.onChange(cb); | ||
| decofileProviderPromise.then((r) => r.onChange(cb)); | ||
| return { | ||
| [Symbol.dispose]: () => { | ||
| }, | ||
| }; | ||
| }, | ||
| revision: () => decofileProviderPromise.then((r) => r.revision()), | ||
| revision: () => { | ||
| if (resolvedProvider) return resolvedProvider.revision(); | ||
| return decofileProviderPromise.then((r) => r.revision()); | ||
| }, | ||
| dispose: () => { | ||
| decofileProviderPromise.then((r) => r?.dispose?.()); | ||
| if (resolvedProvider) { | ||
| resolvedProvider.dispose?.(); | ||
| } else { | ||
| decofileProviderPromise.then((r) => r?.dispose?.()); | ||
| } | ||
| resolvedProvider = null; | ||
| delete decofileCache[endpoint]; | ||
|
Comment on lines
+229
to
268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The
🐛 Proposed fix — guard the cache-setter against post-dispose execution let resolvedProvider: DecofileProvider | null = null;
+ let disposed = false;
decofileProviderPromise.then((r) => {
- resolvedProvider = r;
+ if (!disposed) {
+ resolvedProvider = r;
+ }
});
// … inside dispose: …
dispose: () => {
+ disposed = true;
if (resolvedProvider) {
resolvedProvider.dispose?.();
} else {
decofileProviderPromise.then((r) => r?.dispose?.());
}
resolvedProvider = null;
delete decofileCache[endpoint];
},🤖 Prompt for AI Agents |
||
| }, | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
P2:
resolvedProvidercan be repopulated afterdispose()if the promise resolves later, leaving a stale disposed provider cached. Guard the.thenassignment with a disposed flag (or clear in the dispose promise) so the cached provider cannot be restored after disposal.Prompt for AI agents