Skip to content

fix(mobile): fix mobile components build error #2696

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

Merged
merged 1 commit into from
Dec 26, 2024
Merged

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Dec 25, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added a new dependency for @opentiny/vue-theme-mobile.
    • Introduced several utility functions and components in the adapter for improved component rendering and event handling.
  • Bug Fixes

    • Corrected import paths across various components to ensure proper functionality.
  • Documentation

    • Updated comments and structure for clarity in the adapter.
  • Chores

    • Removed unnecessary import statements and files to streamline the codebase.

Copy link

coderabbitai bot commented Dec 25, 2024

Walkthrough

This pull request involves comprehensive changes to the mobile package's component structure and dependencies. The modifications primarily focus on updating import paths, removing stylesheet imports, adjusting component configurations, and streamlining the Vue common adapter. A new mobile theme dependency has been added to the package, and several utility functions have been introduced or reorganized in the Vue common adapter to improve component management and interaction.

Changes

File Change Summary
packages/mobile/components/container/index.ts Removed LESS stylesheet import
packages/mobile/components/date-picker/src/mobile.vue Updated suffix slot definition using <template> tag
packages/mobile/components/loading/index.ts Modified setupComponent import path
packages/mobile/components/modal/index.ts Updated import paths for createComponent and setupComponent
packages/mobile/components/multi-select-item/src/mobile.vue Removed props import, updated Button component import path
packages/mobile/components/popover/index.ts Removed LESS stylesheet import
packages/mobile/components/tooltip/src/mobile.vue Corrected import path typo
packages/mobile/components/upload/src/mobile.vue Updated defineComponent import path, removed uploadFiles variable
packages/mobile/package.json Added @opentiny/vue-theme-mobile dependency
packages/mobile/vite.config.ts Removed vite-plugin-dts plugin, adjusted build and external dependencies
packages/mobile/vue-common/index.ts Removed specifyPc variable, modified svg function
packages/mobile/vue-common/src/adapter/index.ts Comprehensive refactoring of Vue adapter with new exports and utility functions
packages/mobile/vue-common/src/adapter/vue3/index.ts Entire file deleted
packages/mobile/vue-common/src/adapter/vue3/package.json File removed

Suggested Labels

mobile, dependencies, refactoring, vue-adapter

Poem

🐰 Hopping through code with glee,
Import paths dancing, wild and free!
Vue components restructured with care,
Mobile magic blooming everywhere!
A rabbit's refactor, sleek and bright! 🌟

Possibly Related PRs

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the bug Something isn't working label Dec 25, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (4)
packages/mobile/vue-common/src/adapter/index.ts (4)

25-33: Consider optional chaining for safer property access

In renderComponent, you might simplify the check for view?.value. For instance:

- return () => hooks.h((view && view.value) || component, { ref: 'modeTemplate', ...props, ...attrs, ...extend }, slots)
+ return () => hooks.h(view?.value ?? component, { ref: 'modeTemplate', ...props, ...attrs, ...extend }, slots)

This shortens code and avoids manual ternary or logical AND checks.

🧰 Tools
🪛 Biome (1.9.4)

[error] 32-32: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


64-69: Use optional chaining to simplify the route extraction

Here, instead of:

const route = router && router.currentRoute.value

you could consider optional chaining:

- const route = router && router.currentRoute.value
+ const route = router?.currentRoute?.value

This clarifies the intention without manual checks.


79-90: Refine event broadcasting logic with optional chaining

Multiple checks such as vm.subTree && vm.subTree.children, child.type && child.type.componentName, and component.$emitter && component.$emitter.emit(...) can be converted to optional chaining. For example:

- const children = (vm.subTree && vm.subTree.children) || vm.children
+ const children = vm.subTree?.children || vm.children

- const name = child.type && child.type.componentName
+ const name = child.type?.componentName

- component.$emitter && component.$emitter.emit(eventName, params)
+ component.$emitter?.emit(eventName, params)

This relies on short-circuit checks and clarifies the flow.

🧰 Tools
🪛 Biome (1.9.4)

[error] 79-82: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 84-86: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 88-90: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


303-364: Consider splitting the tools function for better maintainability

The tools function provides routing, i18n, event dispatching, parent/child references, and more. Splitting it into smaller, dedicated helper functions (e.g., separate route logic, separate parent attribute handling) can make the code more understandable and testable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d51590 and 32d7e43.

📒 Files selected for processing (14)
  • packages/mobile/components/container/index.ts (0 hunks)
  • packages/mobile/components/date-picker/src/mobile.vue (1 hunks)
  • packages/mobile/components/loading/index.ts (1 hunks)
  • packages/mobile/components/modal/index.ts (1 hunks)
  • packages/mobile/components/multi-select-item/src/mobile.vue (1 hunks)
  • packages/mobile/components/popover/index.ts (0 hunks)
  • packages/mobile/components/tooltip/src/mobile.vue (1 hunks)
  • packages/mobile/components/upload/src/mobile.vue (1 hunks)
  • packages/mobile/package.json (1 hunks)
  • packages/mobile/vite.config.ts (1 hunks)
  • packages/mobile/vue-common/index.ts (1 hunks)
  • packages/mobile/vue-common/src/adapter/index.ts (2 hunks)
  • packages/mobile/vue-common/src/adapter/vue3/index.ts (0 hunks)
  • packages/mobile/vue-common/src/adapter/vue3/package.json (0 hunks)
💤 Files with no reviewable changes (4)
  • packages/mobile/components/popover/index.ts
  • packages/mobile/vue-common/src/adapter/vue3/package.json
  • packages/mobile/components/container/index.ts
  • packages/mobile/vue-common/src/adapter/vue3/index.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/mobile/components/tooltip/src/mobile.vue
  • packages/mobile/components/modal/index.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/mobile/vue-common/src/adapter/index.ts

[error] 32-32: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 68-71: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 79-82: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 84-86: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 88-90: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 100-100: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 105-107: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 112-113: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 120-120: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 218-218: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 240-242: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 268-269: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 458-461: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (12)
packages/mobile/vue-common/src/adapter/index.ts (3)

1-11: License block looks good

All relevant legal notices are clearly included. No issues with the license header and copyright.


420-441: Ensure custom element detection aligns with all supported browsers

When creating custom elements dynamically, ensure that the document.createElement approach for detection remains valid for all targeted user agents. If your mobile environment includes older browsers, consider polyfills or alternative checks for custom elements (e.g., customElements.get(...)) if needed.


477-487: Validate definitions and usage for newly exported composition APIs

defineComponent, isVue2, isVue3, isVnode, etc., are being exported for use across mobile components. Confirm that internal references to these exports in related files (like plugin setups or external usage) reflect the correct version checks and do not conflict with existing Vue 2 or Vue 3 code.

packages/mobile/vite.config.ts (2)

13-13: Expanded External Dependencies
Including 'vue' and 'xss' in external properly excludes them from the bundle. If these dependencies are used internally, ensure that all references are accounted for and that this aligns with your final distribution strategy.


7-7: Confirm Removal of dts Plugin
It appears the dts plugin was removed from the build. Verify there are no remaining references to it (e.g., in package.json, scripts, or other config files) to prevent potential build or dependency issues.

packages/mobile/components/loading/index.ts (1)

14-14: Consistent Import Path Update
Changing the import path from ../../../vue-common to ../../vue-common maintains consistency with other components in this PR. Verify that any references or relative paths in related modules (e.g., modal/index.ts) use the correct level of directory traversal.

✅ Verification successful

Let me analyze the search results to verify the import path change.

The search results show that vue-common is a core package used throughout the codebase, and it's imported in various ways:

  1. As a workspace dependency in package.json files: "@opentiny/vue-common": "workspace:~"
  2. In source files using relative paths: '../../vue-common'
  3. As a direct import: '@opentiny/vue-common'

Let me verify the specific file and its imports.


Let me check the actual content of the file and its surrounding structure to verify the import path change.


Let me check the directory structure to verify if the import path change is correct.


Import Path Change is Correct

The import path change from ../../../vue-common to ../../vue-common is correct. The directory structure shows that vue-common is located at packages/mobile/vue-common, and the loading component is at packages/mobile/components/loading/index.ts. Therefore, to reach vue-common from the loading component, going up two levels (../../) is the correct relative path.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Confirm that all references to vue-common are consistent across the codebase.
rg -A 3 "vue-common"

Length of output: 66199


Script:

#!/bin/bash
# Check the directory structure around the file
fd loading packages/mobile/components

Length of output: 125


Script:

#!/bin/bash
# Check the content of the file and its directory
cat packages/mobile/components/loading/index.ts
ls -la packages/mobile/components/loading/

Length of output: 1186


Script:

#!/bin/bash
# Check the directory structure to verify the relative path
ls -la packages/mobile/components/
ls -la packages/mobile/vue-common 2>/dev/null || echo "vue-common not found at this level"
ls -la packages/mobile/ 2>/dev/null

Length of output: 4300

packages/mobile/components/date-picker/src/mobile.vue (1)

22-24: Improved Slot Clarity
Using <template #suffix> is a clean, explicit approach to defining the slot. This is a standard Vue convention and helps readability. Looks good!

packages/mobile/components/upload/src/mobile.vue (1)

14-14: Import Path Alignment
Importing defineComponent from the relative path ../../../vue-common appears consistent with other updates in this PR. Confirm that the file structure indeed places vue-common at this level, to avoid tricky import resolution errors.

✅ Verification successful

Let me verify the directory structure to ensure the import path is correct.


Import path is correctly aligned with the codebase structure

The import path ../../../vue-common is consistently used across all mobile components in the codebase. The extensive search results show that this is the standard import pattern used by all 60+ mobile component files for importing from vue-common, confirming that the import path in packages/mobile/components/upload/src/mobile.vue is correctly aligned with the codebase structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check references to `vue-common` in the mobile components upload directory
rg -A 2 "vue-common" packages/mobile/components/upload

Length of output: 310


Script:

#!/bin/bash
# Check if vue-common exists at the expected location
fd vue-common packages/mobile/components

# Check other files in the same directory for similar imports
rg "from.*vue-common" packages/mobile/components

Length of output: 8268

packages/mobile/vue-common/index.ts (1)

234-234: Consider verifying the removal of custom-class.
The destructuring of context.attrs no longer includes custom-class, which might break custom styling in certain scenarios. Ensure that any references to custom-class in parent components or templates have been updated or removed if no longer necessary.

packages/mobile/package.json (1)

35-35: Dependency addition looks good; confirm compatibility.
Adding @opentiny/vue-theme-mobile as a workspace dependency aligns with the theme-driven approach. However, confirm that this addition does not introduce version conflicts or unexpected behavior in existing components.

packages/mobile/components/multi-select-item/src/mobile.vue (2)

52-52: Validate relative import path usage for vue-common.
The import path '../../../vue-common' is consistent with the new structure, but ensure that any refactoring or folder reorganization does not break this relative import in the future.


55-55: Check alignment with new button import path.
Switching from @opentiny/vue-button to a relative path '../../button' may impact shared usage. Verify that the button component is correctly compiled and included, especially if other modules rely on the previous import.

Comment on lines +398 to +418
const parseProps = (propsData) => {
const props = {}

for (const name in propsData) {
if (name === 'class' || name === 'style') {
props[name] = propsData[name]
} else if (name === 'on' || name === 'nativeOn') {
const events = propsData[name]

for (const eventName in events) props[`on${capitalize(camelize(eventName))}`] = events[eventName]
} else if (name === 'attrs' || name === 'props' || name === 'domProps') {
const attrs = propsData[name]

for (const key in attrs) props[key] = attrs[key]
} else {
props[name] = propsData[name]
}
}

return props
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor nested property handling in parseProps

Your large conditional branches (lines 402–414) handle class, style, attrs, props, domProps, and events. Extracting these detail-specific transformations into smaller helper methods clarifies the code and makes future amendments simpler.

@kagol kagol merged commit 13660bc into dev Dec 26, 2024
11 of 21 checks passed
@kagol kagol deleted the fix-mobile-build-error branch April 14, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants