Skip to content
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

fix: the anchor and tabs conflict #5168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Pro-linx
Copy link

@Pro-linx Pro-linx commented Dec 18, 2024

Description

修复使用锚点跳转时,会刷新content区域。若带有锚点地址刷新网页时,标签页重复显示的问题。

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue) > Bug: 当URL存在锚点时,同一个路由会有多个标签页 #5215
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Updated key bindings for dynamic components to improve rendering behavior.
    • Enhanced tab navigation logic for a more consistent route handling experience.
  • Bug Fixes

    • Adjusted tab path handling to streamline tab identification and manipulation.
  • Documentation

    • Minor updates to method signatures for clarity on path usage.

Copy link

changeset-bot bot commented Dec 18, 2024

⚠️ No Changeset found

Latest commit: 180063b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces a systematic change across multiple files in the layout and store modules, focusing on replacing route.fullPath with route.path in key bindings and tab management. This modification affects how routes are tracked and referenced in Vue components and the tabbar store, potentially simplifying route handling and component rendering. The changes are consistent across different components, suggesting a deliberate refactoring of route path management.

Changes

File Change Summary
packages/effects/layouts/src/authentication/form.vue Modified key binding from route.fullPath to route.path
packages/effects/layouts/src/basic/content/content.vue Updated :key attribute for <component> elements to use route.path
packages/effects/layouts/src/basic/tabbar/use-tabbar.ts Changed currentActive to return route.path and updated navigation logic
packages/effects/layouts/src/iframe/iframe-router-view.vue Updated v-for key from item.fullPath to item.path
packages/stores/src/modules/tabbar.ts Replaced fullPath with path in multiple methods and getTabPath function

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • anncwb
  • vince292007

Poem

🐰 Routing paths, once full and wide,
Now trimmed and neat, a smoother ride
From fullPath to path, we dance and leap
Vue components smile, no secrets to keep
A rabbit's refactor, clean and bright! 🚀

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.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review.


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.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (3)
packages/effects/layouts/src/basic/content/content.vue (1)

103-103: LGTM! Consider documenting the route key strategy

The change from route.fullPath to route.path is consistent across both cached and non-cached component scenarios. This effectively prevents unnecessary re-renders when only the URL anchor changes.

Consider adding a comment or documentation explaining the route key strategy, as this is a crucial architectural decision that affects component lifecycle and state management. This will help future maintainers understand why route.path is used instead of route.fullPath.

Also applies to: 109-109

packages/stores/src/modules/tabbar.ts (2)

549-549: LGTM! Consider documenting the path handling behavior

The change to use path instead of fullPath is correct and forms the foundation for fixing the anchor navigation issue. The URL decoding ensures proper handling of special characters in paths.

Consider adding a comment explaining why we use path instead of fullPath:

 /**
  * @zh_CN 获取标签页路径
+ * @description Uses base path without query parameters to ensure consistent tab handling
+ * and prevent duplicate tabs when using anchor navigation
  * @param tab
  */
 function getTabPath(tab: RouteRecordNormalized | TabDefinition) {
   return decodeURIComponent((tab as TabDefinition).path);
 }

Line range hint 1-565: Consider documenting the tab path handling strategy

The systematic change from fullPath to path effectively addresses the anchor navigation issue. However, this represents a significant architectural decision in how tab uniqueness is determined.

Consider:

  1. Adding a comment in the store's documentation explaining this tab path handling strategy
  2. Updating relevant component documentation to clarify that tabs with different query parameters will be treated as the same tab
  3. Adding test cases to verify the behavior with various URL patterns (base paths, query parameters, and anchors)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a97c998 and 180063b.

📒 Files selected for processing (5)
  • packages/effects/layouts/src/authentication/form.vue (1 hunks)
  • packages/effects/layouts/src/basic/content/content.vue (1 hunks)
  • packages/effects/layouts/src/basic/tabbar/use-tabbar.ts (2 hunks)
  • packages/effects/layouts/src/iframe/iframe-router-view.vue (1 hunks)
  • packages/stores/src/modules/tabbar.ts (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/effects/layouts/src/iframe/iframe-router-view.vue
🔇 Additional comments (6)
packages/effects/layouts/src/authentication/form.vue (1)

18-18: LGTM! Verify component state preservation

The change from route.fullPath to route.path is correct and aligns with fixing the anchor navigation issue. This ensures the component doesn't re-render when only the anchor portion of the URL changes.

Let's verify that this component maintains its state correctly with the new key:

#!/bin/bash
# Check if there are any other instances where fullPath might still be used
# that could affect this component's state preservation
rg -g '!*.{json,md}' 'fullPath.*authentication' 
packages/effects/layouts/src/basic/tabbar/use-tabbar.ts (2)

46-46: LGTM! Key change for tab management

The change to use route.path for the current active tab is correct and consistent with the PR's objective to fix anchor-related issues.

Let's verify the tab management behavior:

#!/bin/bash
# Check for any remaining fullPath usage in tab-related code
# that might conflict with this change
rg -g '!*.{json,md}' 'fullPath.*tab'

147-147: LGTM! Verify maximize behavior

The change to use tab.path in the maximize handler ensures consistent navigation behavior and prevents anchor-related issues when maximizing tabs.

Let's verify the maximize functionality:

#!/bin/bash
# Check for any maximize-related handlers that might still use fullPath
rg -g '!*.{json,md}' 'fullPath.*(maximize|restore)'
packages/stores/src/modules/tabbar.ts (3)

191-191: LGTM! Consistent with the tab path handling changes

The change maintains consistency with the new tab path handling approach, ensuring that tabs are compared using their base paths rather than full paths with query parameters.


61-65: LGTM! Verify tab closing behavior with query parameters

The change from fullPath to path looks good and aligns with fixing the anchor navigation issue. This ensures that tabs with the same base path but different query parameters or anchors are treated as the same tab.

Let's verify that tabs with query parameters are handled correctly:

#!/bin/bash
# Search for any special handling of query parameters in tab management
rg -g '!*.{json,lock}' -A 3 'query.*params' .

293-293: Verify if query parameters should be preserved when opening in new window

While the change is consistent with other path handling updates, we should verify if query parameters need to be preserved when opening tabs in new windows. The current implementation might drop important URL parameters.

Let's check how query parameters are handled in new window openings:

#!/bin/bash
# Search for the implementation of openRouteInNewWindow
rg -A 5 'function openRouteInNewWindow' .

# Search for any tests related to opening routes in new windows
rg -g '*.{spec,test}.{ts,js,tsx,jsx}' 'openRouteInNewWindow|openTabInNewWindow' .

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.

1 participant