Skip to content

fix(frontend): MkSwitch自身でチェック状態を持つように#17333

Open
syuilo wants to merge 1 commit into
developfrom
fix-switch-behaviour
Open

fix(frontend): MkSwitch自身でチェック状態を持つように#17333
syuilo wants to merge 1 commit into
developfrom
fix-switch-behaviour

Conversation

@syuilo
Copy link
Copy Markdown
Member

@syuilo syuilo commented Apr 24, 2026

What

MkSwitch自身でチェック状態を持つように

Why

shallowなリアクティビティでmodelValueが渡されている場合、親からtriggerRefしたとしてもMkSwitchに反映されない問題がある
Switch自身でチェック状態を持つようにすることで、オフの状態でクリックしたらオンになり、オンの状態でクリックしたらオフになることが保証される

Additional info (optional)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 24, 2026
@github-actions github-actions Bot added the packages/frontend Client side specific issue/PR label Apr 24, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.92%. Comparing base (8a85ee1) to head (2da1984).

Files with missing lines Patch % Lines
packages/frontend/src/components/MkSwitch.vue 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #17333      +/-   ##
===========================================
- Coverage    24.89%   14.92%   -9.98%     
===========================================
  Files         1150      242     -908     
  Lines        38825    11869   -26956     
  Branches     10774     4019    -6755     
===========================================
- Hits          9667     1771    -7896     
+ Misses       23393     7934   -15459     
+ Partials      5765     2164    -3601     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@syuilo
Copy link
Copy Markdown
Member Author

syuilo commented Apr 24, 2026

Switchが押されても親で実際に値を更新しなければ表示は変わらないという前提で使っている箇所は他の方法で実現するように改修する必要はある

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

MkSwitch が modelValue の shallow reactivity 由来の更新漏れを起こすケースに対応するため、コンポーネント側でチェック状態を保持するように変更するPRです。

Changes:

  • modelValue をローカル state(checked)にミラーし、クリック時にローカル state を先に反転
  • watchprops.modelValue 変更時にローカル state を同期


<script lang="ts" setup>
import { toRefs } from 'vue';
import { ref, toRefs, watch } from 'vue';
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

toRefs is imported but no longer used in this component. This will typically trip lint/TS unused-import checks; please remove it (or use it) to keep the file clean and the build green.

Suggested change
import { ref, toRefs, watch } from 'vue';
import { ref, watch } from 'vue';

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +58
const checked = ref(props.modelValue);

watch(() => props.modelValue, v => {
checked.value = v;
});

const toggle = () => {
if (props.disabled) return;
emit('update:modelValue', !checked.value);
emit('change', !checked.value);

checked.value = !checked.value;
emit('update:modelValue', checked.value);
emit('change', checked.value);
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

modelValue is typed as boolean | Ref<boolean>, but checked is initialized with ref(props.modelValue) and then negated (!checked.value). If a Ref<boolean> is ever passed (e.g. programmatic render), checked.value becomes an object and !checked.value will always be false, breaking toggling and also defeating the intended reactivity fix. Consider normalizing with unref() (and watching unref(props.modelValue)), or otherwise narrowing modelValue to boolean so checked is always a boolean.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages/frontend Client side specific issue/PR size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

2 participants