-
Notifications
You must be signed in to change notification settings - Fork 328
fix: the error issue where the service cannot obtain information #3762
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: release-3.26.0
Are you sure you want to change the base?
Conversation
WalkthroughUpdated Vue 3 adapter’s tools() to resolve the service via root.$getService(vm) when available, otherwise use root.$service. No other API surfaces or exports changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor VM as Vue Component (vm)
participant Adapter as Vue3 Adapter.tools()
participant Root as App Root
VM->>Adapter: tools(vm, root)
alt root has $getService
Adapter->>Root: $getService(vm)
Root-->>Adapter: Service instance (vm-scoped)
else fallback
Adapter->>Root: access $service
Root-->>Adapter: Service instance (root-scoped)
end
Adapter-->>VM: { service, ...otherTools }
note over Adapter: Conditional service resolution introduced
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/vue-common/src/adapter/vue3/index.ts
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/vue-common/src/adapter/vue3/index.ts (1)
packages/vue-hooks/src/vue-emitter.ts (1)
vm
(15-49)
🔇 Additional comments (2)
packages/vue-common/src/adapter/vue3/index.ts (2)
378-378
: LGTM! Backward-compatible service resolution.The conditional logic correctly checks for
$getService
before calling it, falling back to$service
when unavailable. This should resolve the console errors mentioned in the PR objectives.
378-379
: Manually verify service return consistency and run demo testsExisting Playwright specs under
examples/sites/demos/.../custom-service.spec.ts
cover components usingservice
. Ensure both branches (root.$getService(vm)
and fallbackroot.$service
) expose the same API and produce no console errors when running these demos.
isMobileMode: mode === 'mobile', | ||
service: root?.$service, | ||
service: root?.$getService ? root?.$getService(vm) : root?.$service, | ||
getService: () => root?.$getService(vm), |
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.
Critical: Missing existence check could cause runtime errors.
Unlike the service
property at line 378, this getService
function doesn't check if $getService
exists before calling it. When $getService
is unavailable, calling getService()
will throw a TypeError: ... is not a function
.
Apply this diff to add the same backward-compatibility check:
- getService: () => root?.$getService(vm),
+ getService: () => root?.$getService ? root.$getService(vm) : root?.$service,
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
getService: () => root?.$getService(vm), | |
getService: () => root?.$getService ? root.$getService(vm) : root?.$service, |
🤖 Prompt for AI Agents
In packages/vue-common/src/adapter/vue3/index.ts around line 379, the getService
function directly calls root?.$getService(vm) without ensuring $getService is
available; update it to perform the same backward-compatibility check used for
the service property at line 378 (e.g., check that root?.$getService exists and
is a function before calling it) and return undefined (or a no-op) when
$getService is not present so calling getService() cannot throw a TypeError.
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
在于$service的获取不到,导致控制台报错,添加兼容方式即可
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit