Skip to content

fix: Fix the incompatibility issues caused by version upgrade - #7750

Merged
wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_version_upgrade
Nov 9, 2026
Merged

wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_version_upgrade

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: Fix the incompatibility issues caused by version upgrade

hasOpened.value = true
}

const slots = defineSlots<{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here is a concise review of the code changes with potential issues and optimizations:

1. Potential Issue: Race Condition & Performance

  • await nextTick() inside an event handler: While nextTick ensures the DOM updates after Vue re-render, using async/await here adds unnecessary microtask overhead. If hasOpened.value = true triggers a massive re-render (e.g., mounting complex dropdown menus), delaying this assignment might cause a visible flash or layout shift if the UI depends on this flag immediately.
  • Suggestion: Unless you specifically need to wait for a child component's onMounted hook before changing this value, standard synchronous assignment is faster and safer:
    function handleVisibleChange(visible: boolean) {
      if (visible && !hasOpened.value) {
        hasOpened.value = true;
      }
    }
    Only keep nextTick if you are waiting for specific child lifecycles.

2. Code Clarity & Naming

  • Comment Ambiguity: The comment says "首次入场钩子执行后再切换" (Switch after first entry hooks execute). This implies dependency on child lifecycle hooks. If that’s not strictly necessary, remove the complexity. If it is necessary, name the variable/function more explicitly to reflect why we are delaying.
  • Early Return Style: The new early return style (if (!visible || hasOpened.value) return) is cleaner than the original. 👍

3. Optimization Suggestions

  • Remove Unused Import: Check if Fragment and isVNode are still used elsewhere in the file. If they were only imported for logic removed elsewhere, clean them up.
  • Type Safety: Ensure DropdownInstance correctly types handleVisibleChange. Element Plus dropdowns usually emit @visible-change, so confirm the parameter type matches.

4. Edge Case Risk

  • Multiple Rapid Toggles: If the user rapidly opens/closes the dropdown before nextTick resolves, the second true call will skip due to hasOpened.value, but the await nextTick from the first call might still resolve later, redundantly setting hasOpened.value = true again (minor, but inefficient).
    • Fix: Add a guard check inside the async block if kept:
    async function handleVisibleChange(visible: boolean) {
      if (!visible || hasOpened.value) return
      const currentId = ++transitionId // optional: track state versions
      await nextTick()
      if (hasOpened.value === false && transitionId === currentId) {
        hasOpened.value = true
      }
    }

Recommendation

Revert to synchronous assignment unless there is a proven visual bug requiring nextTick. Async operations in visibility handlers should be avoided unless strictly necessary for timing-sensitive animations.

meta: { permission: ({ params }) => perm.knowledge.workspace.image.read(String(params.knowledgeId)), next: 'workspace-knowledge-tag', title: '图片', order: 20, detailMenuVisible: (params) => params.type === KNOWLEDGE_TYPE_KEY.BASE || params.type === KNOWLEDGE_TYPE_KEY.WORKFLOW },
},
{
path: 'tag',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here is the analysis of the provided code diff:

1. Irregularities / Issues

  • None detected (Syntax): The syntax is valid TypeScript/JavaScript and correct Vue Router configuration.
  • Logic Validity: Assuming KNOWLEDGE_TYPE_KEY.WORKFLOW is a defined constant, the logic is sound. It extends the visibility of the "Image" menu item for knowledge bases of type BASE or WORKFLOW.

2. Potential Concerns

  • Readability & Maintainability: As more types are added (e.g., DOC, URL, etc.), this condition (params) => params.type === A || params.type === B will become hard to maintain.
  • Type Safety: Ensure KNOWLEDGE_TYPE_KEY is defined elsewhere in the project. If not imported in this file or the surrounding module, it will cause a build/runtime error.

3. Optimization Suggestions

✅ Recommended Improvement: Use an Allowlist Array

Replace the chained || operators with an array .includes() check. This is cleaner, easier to extend, and less prone to logical errors when adding new types.

Before:

detailMenuVisible: (params) => params.type === KNOWLEDGE_TYPE_KEY.BASE || params.type === KNOWLEDGE_TYPE_KEY.WORKFLOW

After:

const ALLOWED_TYPES_FOR_IMAGE = [
  KNOWLEDGE_TYPE_KEY.BASE,
  KNOWLEDGE_TYPE_KEY.WORKFLOW,
  // Add other types here easily in the future
];

// Inside meta:
detailMenuVisible: (params) => ALLOWED_TYPES_FOR_IMAGE.includes(params.type),

💡 Additional Best Practice

If detailMenuVisible is used similarly across multiple routes (e.g., only showing tag, file, etc., for certain types), consider extracting these permission/visibility rules into separate composable functions or constants files to avoid duplication and ensure consistency.

For example:

// utils/menu-utils.ts
export const isVisibleForWorkspaceTypes = (allowedTypes: string[]) => 
  (params: any) => allowedTypes.includes(params.type);

// In Route config:
meta: {
  ...
  detailMenuVisible: isVisibleForWorkspaceTypes([KNOWLEDGE_TYPE_KEY.BASE, KNOWLEDGE_TYPE_KEY.WORKFLOW])
}

@wangdan-fit2cloud
wangdan-fit2cloud merged commit 1e6ac38 into v3 Nov 9, 2026
3 of 4 checks passed
@wangdan-fit2cloud
wangdan-fit2cloud deleted the pr@v3@fix_version_upgrade branch November 9, 2026 07:07
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.

2 participants