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

feat: lazy load dirs #80

Merged
merged 2 commits into from
May 19, 2024
Merged

feat: lazy load dirs #80

merged 2 commits into from
May 19, 2024

Conversation

elrrrrrrr
Copy link
Member

@elrrrrrrr elrrrrrrr commented May 19, 2024

适配 ref 接口调整,改为异步加载子文件夹

  • 🤖 调整子 useDirs 相关逻辑和 FileTree 子文件夹渲染逻辑
  • 📦 默认不锁直接依赖版本
  • 🔐 由于 validate-npm-package-name 限制,先锁定版本

Summary by CodeRabbit

  • New Features

    • Enhanced FileTree component with additional properties for better directory management.
  • Improvements

    • Updated various packages to their latest versions for improved performance and security.
    • Improved caching and revalidation options in directory fetching.
  • Bug Fixes

    • Fixed issues related to directory fetching by adding new parameters and updating the fetch URL.
  • Chores

    • Added @vercel/node and updated other development dependencies.
    • Added overrides for specific npm packages to ensure compatibility.

@elrrrrrrr elrrrrrrr added the enhancement New feature or request label May 19, 2024
@elrrrrrrr elrrrrrrr requested a review from fengmk2 May 19, 2024 03:09
Copy link

vercel bot commented May 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cnpmweb ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2024 3:09am

Copy link

coderabbitai bot commented May 19, 2024

Walkthrough

The updates primarily involve version bumps for various packages in package.json and enhancements to the FileTree and useDirs functionalities. The FileTree component now handles additional properties (pkgName and spec), and useDirs has been enhanced to accept more parameters for better reusability and caching. These changes aim to improve the overall functionality and maintainability of the codebase.

Changes

File Path Change Summary
package.json Updated versions for multiple dependencies and added @vercel/node.
src/components/FileTree/index.tsx Enhanced FileTree to use pkgName and spec properties.
src/hooks/useFile.ts Modified useDirs to accept additional parameters (path and ignore).
src/slugs/files/index.tsx Introduced spec variable and updated FileTree and CodeViewer components.

🐇 In the land of code, where files align,
Updates and tweaks make systems shine.
With pkgName and spec in the tree,
Our directories now roam wild and free.
Dependencies fresh, our code refined,
A rabbit's touch, improvements combined.
Hopping through code, we celebrate,
A system robust, a future great! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@elrrrrrrr elrrrrrrr changed the title Lazy load dirs feat: lazy load dirs May 19, 2024
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

Out of diff range and nitpick comments (1)
src/components/FileTree/index.tsx (1)

18-19: Properly document the new props pkgName and spec in the FileTree component to ensure clarity for future developers.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4d41519 and baa53b2.
Files selected for processing (4)
  • package.json (1 hunks)
  • src/components/FileTree/index.tsx (6 hunks)
  • src/hooks/useFile.ts (1 hunks)
  • src/slugs/files/index.tsx (2 hunks)
Additional comments not posted (9)
package.json (5)

17-17: Ensure that using a version range for @types/react-dom does not introduce type inconsistencies with other packages.


27-27: Verify that the version range for next does not break existing features due to potential breaking changes in minor updates.


29-31: Confirm compatibility of the version ranges for react and react-dom with other React ecosystem packages.

Verification successful

The search did not find any other React ecosystem packages in package.json. This suggests that there are no additional dependencies that could conflict with the updated version ranges for react and react-dom.

  • react: "^18.2.0"
  • react-dom: "^18.2.0"
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for compatibility issues with other React ecosystem packages.

# Test: Search for other React ecosystem packages that might be affected.
rg --type json '"react"'

Length of output: 63



Script:

#!/bin/bash
# Description: Check for other React ecosystem packages in package.json that might be affected by the version range update.

# Test: Search for common React ecosystem packages.
rg --type json '"react-router"'
rg --type json '"redux"'
rg --type json '"react-redux"'
rg --type json '"@testing-library/react"'

Length of output: 137


38-38: Confirm the necessity and usage of @vercel/node in the project's development environment.


49-52: Ensure that the override for npm-package-arg to use validate-npm-package-name version 5.0.0 is aligned with the project's dependency management policies.

src/slugs/files/index.tsx (3)

17-18: Good use of a fallback mechanism with version || 'latest' to ensure spec is always defined.


47-53: Ensure that the FileTree component's new props pkgName and spec are properly documented and used consistently across the project.


55-55: Confirm that the CodeViewer component's use of the spec variable aligns with its intended functionality.

Verification successful

The CodeViewer component correctly uses the spec variable as part of the useFileContent hook to fetch the file content based on the pkgName and spec. This aligns with its intended functionality.

  • src/components/CodeViewer.tsx:
    export const CodeViewer = ({
      selectedFile,
      pkgName,
      spec,
    }: {
      selectedFile: File | undefined;
      pkgName: string;
      spec?: string;
    }) => {
      const { data: code } = useFileContent({ fullname: pkgName, spec }, selectedFile?.path || '');
      // ... rest of the component
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the alignment of `spec` usage in `CodeViewer` with its functionality.

# Test: Search for the implementation details of `CodeViewer`.
rg --type typescript --files-with-matches 'CodeViewer'

Length of output: 89



Script:

#!/bin/bash
# Description: Locate the `CodeViewer` component and inspect its implementation.

# Search for the `CodeViewer` component definition.
rg --type tsx --files-with-matches 'CodeViewer'

# Once located, display the implementation details of `CodeViewer`.
rg 'CodeViewer' $(fd -e tsx)

Length of output: 1784



Script:

#!/bin/bash
# Description: Display the implementation details of the `CodeViewer` component in `src/components/CodeViewer.tsx`.

# Display the implementation of the `CodeViewer` component.
rg 'export const CodeViewer' src/components/CodeViewer.tsx -A 50

Length of output: 1458

src/components/FileTree/index.tsx (1)

30-31: Ensure that the SubTree component's new props pkgName and spec are used consistently and effectively throughout the component.

Verification successful

The pkgName and spec props are indeed being passed to the SubTree component and utilized within it. Here are the relevant locations in the codebase:

  • src/components/FileTree/index.tsx:
    • SubTree component definition includes pkgName and spec in its props.
    • SubTree is instantiated with pkgName and spec being passed as props.

This confirms that the new props are used consistently and effectively.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the consistent and effective use of `pkgName` and `spec` in the `SubTree` component.

# Test: Search for other instances where `SubTree` is used.
rg --type typescript --files-with-matches 'SubTree'

Length of output: 86



Script:

#!/bin/bash
# Description: Verify the consistent and effective use of `pkgName` and `spec` in the `SubTree` component.

# Test: Search for other instances where `SubTree` is used.
rg --type ts --files-with-matches 'SubTree'

Length of output: 77



Script:

#!/bin/bash
# Description: Inspect the usage of `SubTree` within `src/components/FileTree/index.tsx` to verify the consistent and effective use of `pkgName` and `spec`.

# Test: Search for `SubTree` component usage within `src/components/FileTree/index.tsx`.
rg 'SubTree' src/components/FileTree/index.tsx

Length of output: 190



Script:

#!/bin/bash
# Description: Extract the relevant code snippets around the `SubTree` instances within `src/components/FileTree/index.tsx` to verify the usage of `pkgName` and `spec`.

# Test: Extract lines around the `SubTree` instances.
rg -A 5 -B 5 'SubTree' src/components/FileTree/index.tsx

Length of output: 913

Comment on lines +43 to +58
export const useDirs = (info: PkgInfo, path = '', ignore = false) => {
// https://github.com/cnpm/cnpmcore/issues/680
// 请求文件路径存在性能问题,手动关闭 revalidate ,拆分多次请求
return useSwr(ignore ? null : `dirs: ${info.fullname}_${info.spec}_${path}`, {
revalidateOnFocus: false,
revalidateOnReconnect: false,
// 本地缓存优先
refreshInterval: 0,
fetcher: async () => {
return fetch(`${REGISTRY}/${info.fullname}/${info.spec}/files${path}/?meta`)
.then((res) => res.json())
.then((res) => {
sortFiles(res.files);
return Promise.resolve(res);
});
}
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate that the useDirs function is defined in src/hooks/useFile.ts with the parameters path and ignore having default values of '' and false, respectively. However, there is no documentation or comments explaining these parameters.

  • src/hooks/useFile.ts: export const useDirs = (info: PkgInfo, path = '', ignore = false) => {

To ensure clarity and maintainability, please add documentation comments for the useDirs function, specifically explaining the purpose and default values of the path and ignore parameters.

Analysis chain

Ensure that the new parameters path and ignore in useDirs are well-documented and their default values are appropriately set.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the documentation and default values for `path` and `ignore` in `useDirs`.

# Test: Search for the documentation of `useDirs`.
rg --type typescript --files-with-matches 'useDirs'

Length of output: 86



Script:

#!/bin/bash
# Description: Verify the documentation and default values for `path` and `ignore` in `useDirs`.

# Test: Search for the definition of `useDirs` and check for documentation.
rg --type ts --pattern 'useDirs'

# Test: Search for the default values of `path` and `ignore` in `useDirs`.
rg --type ts --pattern 'useDirs' -A 5

Length of output: 894



Script:

#!/bin/bash
# Description: Verify the documentation and default values for `path` and `ignore` in `useDirs`.

# Test: Search for the definition of `useDirs` and check for documentation.
rg 'useDirs' --type ts -A 5

Length of output: 1998

@fengmk2 fengmk2 merged commit 1404458 into main May 19, 2024
6 checks passed
@fengmk2 fengmk2 deleted the lazy-load-dirs branch May 19, 2024 03:26
@elrrrrrrr elrrrrrrr mentioned this pull request May 20, 2024
fengmk2 pushed a commit that referenced this pull request May 20, 2024
> 更新 #80 实现,添加 loading 交互
> 例如  `/package/zoningjs/files?version=2.0.20` 加载事件比较久
* ⌛ FileIcon 添加 isLoading 逻辑

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added a loading indicator to the FileTree component to improve user
experience during data fetching.
- Modified the Icon function in icon.tsx to accept default parameters
for more flexible usage.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants