Skip to content

fix(stage-ui): skip optimistic updates before apply#1304

Merged
Garfield550 merged 2 commits intomoeru-ai:mainfrom
Gujiassh:fix/optimistic-skip-guard
Mar 12, 2026
Merged

fix(stage-ui): skip optimistic updates before apply#1304
Garfield550 merged 2 commits intomoeru-ai:mainfrom
Gujiassh:fix/optimistic-skip-guard

Conversation

@Gujiassh
Copy link
Contributor

Summary

  • move the skipActionIf() guard ahead of apply() so skipped optimistic mutations do not leave phantom UI state behind
  • add a focused regression in packages/stage-ui/src/composables/use-optimistic.test.ts that proves skipped mutations do not call apply() or action()
  • keep the change localized to the shared stage-ui composable layer, away from the previously shipped Telegram message fixes

Validation

  • pnpm -F @proj-airi/stage-ui exec vitest run src/composables/use-optimistic.test.ts
  • pnpm -F @proj-airi/stage-ui typecheck
  • pre-commit hook ran moeru-lint --fix on the staged files successfully during commit

Notes

  • A root-level pnpm lint:fix attempt still reports unrelated pre-existing lint issues elsewhere in the monorepo, but the touched composable files passed the staged-file lint hook and the targeted test/typecheck flow

Avoid leaving phantom optimistic state behind when a mutation is intentionally skipped by checking the guard before applying the optimistic update.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the useOptimisticMutation composable to correctly handle skipped optimistic updates. By reordering the execution of the skipActionIf guard, it prevents the application of temporary UI states when the underlying action is intentionally bypassed, thereby eliminating potential phantom UI elements and ensuring a more consistent user experience.

Highlights

  • Optimistic Update Logic: The skipActionIf() guard in useOptimisticMutation has been moved to execute before apply(). This ensures that if an action is skipped, no optimistic UI state is applied, preventing "phantom" UI elements.
  • Regression Test Added: A new regression test was added to use-optimistic.test.ts to explicitly verify that when skipActionIf() returns true, neither apply() nor action() are called, and the state remains unchanged.
Changelog
  • packages/stage-ui/src/composables/use-optimistic.test.ts
    • Added a new test case to verify that optimistic state is not applied when skipActionIf returns true.
  • packages/stage-ui/src/composables/use-optimistic.ts
    • Reordered the skipActionIf check to occur before the apply function call within the useOptimisticMutation composable.
Activity
  • The changes were validated by running pnpm -F @proj-airi/stage-ui exec vitest run src/composables/use-optimistic.test.ts.
  • Typechecking was performed using pnpm -F @proj-airi/stage-ui typecheck.
  • Pre-commit hooks successfully ran moeru-lint --fix on the staged files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

⏳ Approval required for deploying to Cloudflare Workers (Preview) for stage-web.

Name Link
🔭 Waiting for approval For maintainers, approve here

Hey, @nekomeowww, @sumimakito, @luoling8192, @LemonNekoGH, kindly take some time to review and approve this deployment when you are available. Thank you! 🙏

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where optimistic updates could result in a phantom UI state if the action was skipped. The fix correctly moves the skipActionIf guard before the apply call, ensuring that no optimistic state is set when an action is skipped. A new regression test has been added to verify this behavior, confirming that apply() and action() are not called when skipActionIf returns true. The changes are well-contained and effectively resolve the issue.

@Garfield550
Copy link
Collaborator

No place uses the useOptimisticMutation hook, but LGTM

@Garfield550 Garfield550 merged commit 41ce282 into moeru-ai:main Mar 12, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants