Skip to content

fix: fix some issue on preview page#568

Merged
hexqi merged 1 commit intoopentiny:refactor/developfrom
chilingling:fix/previewImportMap
Jun 11, 2024
Merged

fix: fix some issue on preview page#568
hexqi merged 1 commit intoopentiny:refactor/developfrom
chilingling:fix/previewImportMap

Conversation

@chilingling
Copy link
Member

@chilingling chilingling commented Jun 11, 2024

English | 简体中文

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)
  • Built its own designer, fully self-validated

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:

Background and solution

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

    • Introduced @opentiny/vue-icon dependency in both designer-demo and design-core projects.
  • Improvements

    • Updated the CDN domain in the development environment configuration for better reliability.
    • Modified script source paths in HTML for consistent loading.
    • Enhanced initPreview function to support lifecycle hooks for better customization.
  • Refactor

    • Refactored import map handling to dynamically use environment variables.
    • Improved modularity by exporting importMap through a new function.
  • Bug Fixes

    • Ensured lifecycle hooks are correctly initialized before application creation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 11, 2024

Walkthrough

The recent updates enhance the designer-demo and design-core packages by introducing a new dependency (@opentiny/vue-icon), updating CDN references, and refining script initialization processes. Key changes include updating environment variables, modifying import paths, and adding lifecycle hooks to the initPreview function for better control and customization during app initialization.

Changes

Files/Paths Change Summary
designer-demo/env/.env.development Updated VITE_CDN_DOMAIN value from https://npm.onmicrosoft.cn to https://unpkg.com.
designer-demo/package.json, packages/design-core/package.json Added @opentiny/vue-icon dependency with version ~3.14.0.
designer-demo/preview.html Changed script source path from relative (./src/preview.js) to absolute (/src/preview.js).
designer-demo/src/preview.js Added imports, a new hook (beforeAppCreate), and modified initPreview to include this hook in lifecycle.
packages/design-core/src/preview/src/main.js Modified initPreview to accept lifeCycles parameter and invoke beforeAppCreate if present.
packages/design-core/src/preview/src/preview/Preview.vue Updated import statement to use getImportMap and replaced return importMap with return getInitImportMap().
packages/design-core/src/preview/src/preview/importMap.js Refactored replacePlaceholder to use useEnv().VITE_CDN_DOMAIN and exported importMap through getImportMap function.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant EnvFile as .env.development
    participant App as Application
    participant CDN as CDN (unpkg.com)

    Developer->>EnvFile: Update VITE_CDN_DOMAIN
    EnvFile->>App: Provide updated CDN domain
    App->>CDN: Fetch resources from new CDN (unpkg.com)
    CDN-->>App: Serve requested resources
    App-->>Developer: Application runs with resources from unpkg.com

    Developer->>App: Add @opentiny/vue-icon dependency
    App->>App: Install and use new dependency
Loading
sequenceDiagram
    participant Developer
    participant PreviewJS as preview.js
    participant MainJS as main.js
    participant Hook as beforeAppCreate Hook

    Developer->>PreviewJS: Add imports and beforeAppCreate hook
    PreviewJS->>MainJS: Pass lifeCycles with beforeAppCreate to initPreview
    MainJS->>Hook: Invoke beforeAppCreate if present
    Hook-->>MainJS: Execute custom initialization
    MainJS->>Developer: App initialized with custom lifecycle
Loading

Poem

In a world of code where changes flow,
New icons shine, dependencies grow.
From npm to unpkg, a swift domain,
Scripts now absolute, no path in vain.
Hooks that breathe life, before apps create,
A rabbit's joy in each update! 🐇✨


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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.

@hexqi hexqi merged commit d99516b into opentiny:refactor/develop Jun 11, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e15e6c4 and aa3564e.

Files selected for processing (8)
  • designer-demo/env/.env.development (1 hunks)
  • designer-demo/package.json (1 hunks)
  • designer-demo/preview.html (1 hunks)
  • designer-demo/src/preview.js (1 hunks)
  • packages/design-core/package.json (1 hunks)
  • packages/design-core/src/preview/src/main.js (1 hunks)
  • packages/design-core/src/preview/src/preview/Preview.vue (2 hunks)
  • packages/design-core/src/preview/src/preview/importMap.js (1 hunks)
Files skipped from review due to trivial changes (3)
  • designer-demo/env/.env.development
  • designer-demo/package.json
  • designer-demo/preview.html
Additional comments not posted (8)
designer-demo/src/preview.js (2)

13-16: Ensure proper usage of imported modules and hooks.

The imports and the new beforeAppCreate hook are correctly defined and used. Please ensure that all necessary tests cover these new imports and the hook functionality.

Also applies to: 18-20


22-29: Validate the integration of the beforeAppCreate hook in the initPreview function.

Verification successful

The beforeAppCreate hook is properly integrated and called within the initPreview function in packages/design-core/src/preview/src/main.js.

  • The beforeAppCreate hook is destructured from the lifeCycles object.
  • The hook is conditionally called with beforeAppCreate?.().

Locations:

  • packages/design-core/src/preview/src/main.js, lines 20 and 23.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `beforeAppCreate` hook is properly integrated and called within the `initPreview` function.

# Test: Search for the function usage. Expect: Only occurances of the new signature with the hook.
rg --type javascript $'initPreview'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify that the `beforeAppCreate` hook is properly integrated and called within the `initPreview` function.

# Test: Search for the function usage. Expect: Only occurrences of the new signature with the hook.
rg --type js 'initPreview'

Length of output: 342



Script:

#!/bin/bash
# Description: Extract the `initPreview` function definition to verify the integration of the `beforeAppCreate` hook.

# Test: Extract the `initPreview` function definition.
ast-grep --lang javascript --pattern $'export const initPreview = ({ registry, lifeCycles = {} }) => {
  $$$
}' packages/design-core/src/preview/src/main.js

Length of output: 1310

packages/design-core/src/preview/src/preview/importMap.js (2)

22-22: Ensure the replacePlaceholder function correctly handles environment variables.

The modification to use useEnv().VITE_CDN_DOMAIN ensures that the environment variable is dynamically fetched, which is a good practice for maintainability and adaptability.


25-32: Check the correctness and efficiency of the getImportMap function.

The getImportMap function is well-implemented, dynamically constructing the import map based on environment-specific parameters. Ensure comprehensive tests cover this functionality.

packages/design-core/src/preview/src/main.js (1)

19-23: Validate the integration of lifecycle hooks in the initPreview function.

The addition of the lifeCycles parameter and the conditional invocation of beforeAppCreate are correctly implemented. Ensure that this change is well-documented and tested.

packages/design-core/package.json (1)

94-94: Confirm the necessity and compatibility of new dependencies.

Verification successful

The new dependency @opentiny/vue-icon is indeed used across multiple files in the codebase, confirming its necessity. Additionally, there are no version conflicts with other dependencies.

  • packages/design-core/package.json: The dependency is listed as ~3.14.0.
  • Various files import and use components from @opentiny/vue-icon.

This confirms that the addition of @opentiny/vue-icon is both necessary and compatible with the existing codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the compatibility and necessity of the new dependencies.

# Test: Check for compatibility issues and ensure they are necessary for the project.
rg --type json $'dependencies'

Length of output: 4003



Script:

#!/bin/bash
# Search for the usage of @opentiny/vue-icon in the codebase
rg '@opentiny/vue-icon'

# Check for version conflicts with other dependencies
jq '.dependencies' packages/design-core/package.json | grep '@opentiny/vue-icon'

Length of output: 32946

packages/design-core/src/preview/src/preview/Preview.vue (2)

22-22: The import change from getImportMap to getInitImportMap looks good.


111-111: Refactoring to use getInitImportMap() centralizes import map construction, which is a good practice.

Verification successful

The function getInitImportMap is defined in the importMap file as getImportMap. It constructs the import map by merging entries from importMapJSON and search parameters, replacing placeholders with actual values. This centralizes the import map logic, which is a good practice.

  • getInitImportMap is correctly defined and implemented in importMap.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the complete functionality of `getInitImportMap` in various scenarios.

# Test: Search for the function usage and test cases. Expect: Comprehensive handling of scenarios.
rg --type javascript $'getInitImportMap'

Length of output: 74



Script:

#!/bin/bash
# Description: Verify the complete functionality of `getInitImportMap` in various scenarios.

# Test: Search for the function usage and test cases. Expect: Comprehensive handling of scenarios.
rg 'getInitImportMap'

Length of output: 230



Script:

#!/bin/bash
# Description: Locate and review the definition of `getInitImportMap` in `./importMap`.

# Find the file `importMap` and search for the definition of `getInitImportMap`.
fd 'importMap' | xargs rg 'function getInitImportMap'

Length of output: 53



Script:

#!/bin/bash
# Description: Locate and review the definition of `getInitImportMap` in `./importMap`.

# Find the file `importMap` and search for the definition of `getInitImportMap` using a broader pattern.
fd 'importMap' | xargs rg 'getInitImportMap'

Length of output: 42



Script:

#!/bin/bash
# Description: Locate and review the definition of `getInitImportMap` in the entire codebase.

# Search for the definition of `getInitImportMap` in all files.
rg 'getInitImportMap'

Length of output: 230



Script:

#!/bin/bash
# Description: Locate and review the contents of the `importMap` file to find the definition of `getInitImportMap`.

# Find the file `importMap` and display its contents.
fd 'importMap' | xargs cat

Length of output: 2966

yy-wow pushed a commit to yy-wow/tiny-engine that referenced this pull request Oct 10, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 26, 2024
14 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 27, 2024
14 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jan 26, 2025
14 tasks
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