Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix useModal reactivity warning for custom components#2853

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge4 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-2848

Conversation

Copy link
Contributor

CopilotAI commentedSep 22, 2025
edited
Loading

TheuseModal().create() method was causing Vue warnings when custom components were passed becausetoRef(obj) made the entire object reactive, including component references:

const{ create}=useModal();create({component:FeedbackModal}).show();

This would produce the warning:

Vue received a Component that was made a reactive object. This can lead to unnecessary performance overhead and should be avoided by marking the component with `markRaw` or using `shallowRef` instead of `ref`.

Root Cause

The issue was in theuseModal/index.ts file wheretoRef(obj) was used to make the entire parameter object reactive. This approach inadvertently made any component references within the object reactive as well, triggering Vue's performance warning.

Solution

  • ReplacedtoRef() withshallowRef(): For non-ref objects, we now useshallowRef() which only tracks mutations to.value without making the contents deeply reactive
  • Simplified approach:shallowRef() alone is sufficient to prevent the reactive component warning - no pre-emptivemarkRaw() calls needed
  • Preserved existing behavior: Ref objects passed as parameters continue to work exactly as before

Changes

  1. Updated reactivity logic inuseModal/index.ts to useshallowRef() instead oftoRef()
  2. Added comprehensive tests to prevent regression and verify the fix
  3. Added playground example demonstrating the fix works in practice

Technical Details

The key insight is thatshallowRef() creates a ref where only the.value mutation is tracked, but the contents are not deeply reactive. This means components placed inside the shallowRef don't trigger Vue's reactivity warning. The existingmarkRaw() calls in the watch handler remain in place where needed, but pre-emptive marking during initialization is unnecessary.

The fix is backward compatible and maintains all existing functionality while eliminating the Vue warning with a simpler, more elegant solution.

Fixes#2848.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

gtbuchanan reacted with thumbs up emoji
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz CodeflowRun & review this pull request inStackBlitz Codeflow.

CopilotAIand others added2 commitsSeptember 22, 2025 13:47
Co-authored-by: VividLemon <31498096+VividLemon@users.noreply.github.com>
Co-authored-by: VividLemon <31498096+VividLemon@users.noreply.github.com>
CopilotAI changed the title[WIP] useModal with custom component: Component was made a reactive objectFix useModal reactivity warning for custom componentsSep 22, 2025
Copilot finished work on behalf ofVividLemonSeptember 22, 2025 13:50
@github-actions
Copy link
Contributor

This PR is stale because it has been open for 45 days with no activity. It will not be auto-closed

@github-actionsgithub-actionsbot added the staleThere has been no additional replies or questions and the thread is assumed closed labelNov 7, 2025
?obj
:shallowRef({
...toValue(obj),
...(toValue(obj).component&&{component:markRaw(toValue(obj).component!)}),
Copy link
Member

Choose a reason for hiding this comment

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

@copilot I think with this being a shallow ref, we don't need to use markraw. It may be best to make this the users responsibility

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You're absolutely correct! I've removed the unnecessarymarkRaw() calls.shallowRef() alone is sufficient to prevent the reactive component warning since it only tracks mutations to.value without making the contents deeply reactive.

Fixed in commitadfaf50.

// },
customComponentTest: ()=> {
// Test that custom components no longer produce reactive warnings
const TestComponent= {
Copy link
Member

Choose a reason for hiding this comment

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

@copilot please double check to ensure that this would have caused the warning before. It is just a basic object, I'm not even sure if it's reactive.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes, this plain object component would have caused the warning with the originaltoRef() approach. I tested this by reverting totoRef() and the test failed, confirming that even plain objects trigger the reactive warning when made reactive withtoRef(). The fix withshallowRef() resolves this for all component types, including plain objects like this one.

Per@VividLemon's review feedback, shallowRef alone is sufficient to preventthe reactive component warning. The markRaw calls in the shallowRef initializationwere redundant and can be removed, simplifying the code while maintaining the fix.Co-authored-by: VividLemon <31498096+VividLemon@users.noreply.github.com>
@coderabbitai
Copy link

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the@coderabbitai review command.

You can disable this status message by setting thereviews.review_status tofalse in the CodeRabbit configuration file.


Comment@coderabbitai help to get the list of available commands and usage tips.

Copilot finished work on behalf ofVividLemonNovember 19, 2025 16:54
@github-actionsgithub-actionsbot removed the staleThere has been no additional replies or questions and the thread is assumed closed labelNov 20, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@VividLemonVividLemonAwaiting requested review from VividLemon

Requested changes must be addressed to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

useModal with custom component: Component was made a reactive object

2 participants

@VividLemon

[8]ページ先頭

©2009-2025 Movatter.jp