Repository navigation
fix: Front end loading sequence - #7952
Conversation
| import router from '@/router/admin' | ||
| import { pinia, useStore } from '@/stores/admin' | ||
| import '@/styles/tailwind.css' | ||
| import '@/styles/index.scss' |
There was a problem hiding this comment.
The change moves import router from '@/router/admin' earlier. Assessment:
-
Circular dependency risk (high concern). The added comment claims the reorder breaks a cycle, but importing
routerearlier generally makes the cycle worse, not better: ifrouter/adminimportspermission(orresource-context, which importsrouter), then evaluatingrouterfirst can mean its top-levelpermread happens beforepermissionhas initialized — exactly the failure the comment describes. The comment's reasoning appears self-contradictory and should be verified with a real circular-dependency tool (madge,dpdm) rather than trusted. -
Fragile import ordering. Relying on ES module evaluation order to fix an init bug is brittle. Imports are hoisted and evaluated depth-first per spec; comments ("勿移动"/do not move) won't enforce this in future refactors, lint autofix, or bundler deduplication. Prefer a structural fix:
- Break the cycle properly (lazy access via getter/function, e.g. read
perminside a guard hook rather than at module top level). - Or inject dependencies explicitly instead of module-level singletons.
- Break the cycle properly (lazy access via getter/function, e.g. read
-
Comment quality. It mixes English and Chinese in a codebase commit hunk; ensure it matches project convention. It also asserts a causal claim that is unverified. If kept, reference the issue/ticket number.
-
No other irregularities in the diff itself: unused imports? All still used.
pinia, useStoregrouping unchanged. No side-effect ordering issue for CSS (CSS imports at the end are fine for Vitest/build but note some bundlers require CSS imports before component usage — unrelated here). -
Optimization suggestion: add an ESLint rule (
import/orderwithpathGroups) to encode intended ordering explicitly, so intent is enforced by tooling rather than comments. Consider dynamicimport()or a factory function forrouterto genuinely eliminate the cycle.
Verdict: Functional correctness is uncertain; the comment's rationale looks backwards. Recommend verifying the dependency graph and solving the cycle structurally instead of via import order.
fix: Front end loading sequence