-
Notifications
You must be signed in to change notification settings - Fork 699
fix: check compatibility when reusing previewer bytecode cache #3190
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
Conversation
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.
Pull Request Overview
Fix compatibility handling when reusing previewer bytecode cache by validating cache and surfacing a user-visible error when incompatible.
- Add compatibility check before invoking previewer; short-circuit to an error render if incompatible
- Introduce peek_error to clear preview area and render a formatted error via MgrProxy
- Add Area conversion from ratatui::layout::Rect to streamline passing layout rects into rendering APIs
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| yazi-plugin/src/isolate/peek.rs | Adds compatibility check and UI error rendering path; updates imports for Error/Renderable and MgrProxy usage |
| yazi-binding/src/elements/area.rs | Adds Fromratatui::layout::Rect for Area to enable passing ratatui Rects directly into APIs expecting Area |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let ct = CancellationToken::new(); | ||
| if let Some(c) = LOADER.read().get(id) { | ||
| if c.sync_peek { | ||
| if let Err(e) = Loader::compatible_or_error(id, c) { | ||
| peek_error(file, mime, skip, e); | ||
| return None; | ||
| } else if c.sync_peek { | ||
| peek_sync(cmd, file, mime, skip); | ||
| } else { | ||
| peek_async(cmd, file, mime, skip, ct.clone()); |
Copilot
AI
Sep 21, 2025
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.
The CancellationToken is created even when we immediately return on incompatibility or take the sync path. Initialize it only in the async branch to avoid unnecessary allocation and cloning. Example: move let ct = CancellationToken::new(); into the else { ... } branch before calling peek_async (and return it from there if applicable).
| fn peek_error(file: yazi_fs::File, mime: Symbol<str>, skip: usize, error: anyhow::Error) { | ||
| let area = LAYOUT.get().preview; | ||
| MgrProxy::update_peeked(UpdatePeekedOpt { | ||
| lock: PreviewLock { | ||
| url: file.url, | ||
| cha: file.cha, | ||
| mime: mime.to_string(), | ||
| skip, | ||
| area: area.into(), | ||
| data: vec![ | ||
| Renderable::Clear(yazi_binding::elements::Clear { area: area.into() }), | ||
| Renderable::from(Error::custom(error.to_string())).with_area(area), | ||
| ], | ||
| }, | ||
| }); | ||
| } |
Copilot
AI
Sep 21, 2025
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.
[nitpick] Consider logging the compatibility error before updating the UI to match the error logging done in the async path and aid diagnostics in headless logs. For example: tracing::error!(error = %error, \"Previewer cache incompatible; rendering error\").
| impl From<Rect> for Area { | ||
| fn from(rect: Rect) -> Self { Self::Rect(rect) } | ||
| } | ||
|
|
Copilot
AI
Sep 21, 2025
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.
[nitpick] Add a brief doc comment explaining why this conversion exists (e.g., to allow passing ratatui::layout::Rect directly to APIs expecting Area). This helps future readers understand the intent and usage contexts.
| /// Allows passing `ratatui::layout::Rect` directly to APIs expecting `Area`. |
Fixes #3185