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

Hotfix: Expand button for code block #5300

Merged
merged 5 commits into from
Aug 21, 2024

Conversation

lloydzhou
Copy link
Member

@lloydzhou lloydzhou commented Aug 21, 2024

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

  1. add reload button

📝 补充信息 | Additional Information

fixed #5291

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a reload functionality in the HTMLPreview component, allowing parent components to refresh the iframe content.
    • Added a reload button in the PreCode component for easier user interaction.
  • Bug Fixes

    • Improved internal state management in the PreCode component for better performance and responsiveness.
  • Style

    • Enhanced the presentation of code blocks and user interaction elements.

Copy link

vercel bot commented Aug 21, 2024

@lloydzhou is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

Your build has completed!

Preview deployment

Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Walkthrough

The recent updates enhance the HTMLPreview and PreCode components by integrating a reload feature, allowing parent components to trigger iframe reloads using React's forwardRef and useImperativeHandle. The PreCode component introduces a reload button, improving user interaction. These changes optimize code structure and enrich the user interface, ensuring a more responsive and dynamic experience.

Changes

Files Change Summary
app/components/artifacts.tsx, app/components/markdown.tsx Refactored HTMLPreview to support external control with a reload method. Added a reload button in PreCode and refined internal logic for improved handling of code previews.

Sequence Diagram(s)

sequenceDiagram
    participant Parent as Parent Component
    participant Preview as HTMLPreview Component
    participant Button as PreCode Button

    Parent->>Preview: Calls reload()
    Preview->>Preview: Generate new frameId (nanoid)
    Preview->>Preview: Update iframe with new frameId
    Button->>Preview: Trigger reload with IconButton
Loading

🐰 "In the meadow where code does play,
A button now brightens the day.
With a hop and a leap, it reloads with cheer,
Let’s dance with the changes, for springtime is here!
With frames that refresh and styles that delight,
Our coding adventure is a splendid sight!" 🥕

Assessment against linked issues

Objective Addressed Explanation
HTML preview functionality restored (#5291)
Improved user experience with reload option
Ensure consistency of code rendering Unclear if all edge cases are handled.

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 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a6b14c7 and b0e9a54.

Files selected for processing (3)
  • app/components/artifacts.tsx (8 hunks)
  • app/components/markdown.tsx (6 hunks)
  • app/styles/globals.scss (2 hunks)
Additional comments not posted (9)
app/styles/globals.scss (1)

Line range hint 307-319: Ensure consistent pointer event handling.

The pointer-events: none; on .show-hide-button disables interactions for the entire button, while pointer-events: auto; on the nested button re-enables them. This setup is correct for allowing interaction only with the button itself, but ensure this behavior is intended and consistent across different browsers.

Consider testing this behavior across multiple browsers to ensure consistent user experience.

app/components/artifacts.tsx (4)

26-36: Refactor using forwardRef and useImperativeHandle is well-implemented.

The use of forwardRef and useImperativeHandle to expose the reload method enhances the component's flexibility. Ensure that all usages of HTMLPreview are updated to handle the ref correctly.


63-67: Verify the reload method functionality.

The reload method updates the frameId using nanoid(), which should trigger a re-render of the iframe. Ensure that this method is tested to confirm it behaves as expected, especially in different scenarios where the iframe content needs refreshing.

Consider adding unit tests to verify the reload functionality.


79-84: Check for correct script injection in srcDoc.

The script for ResizeObserver is appended to the props.code. Ensure that the script is correctly injected and doesn't interfere with existing scripts or content within the code.

Test the srcDoc rendering with various HTML content to ensure compatibility.


231-236: Ensure ReloadButtonIcon integration is seamless.

The addition of the reload button in the Artifacts component is a useful enhancement. Ensure that the button's functionality is intuitive and doesn't disrupt the user experience.

app/components/markdown.tsx (4)

70-70: Addition of previewRef is appropriate.

The introduction of previewRef for managing the HTMLPreview component is a good approach. Ensure that the ref is correctly initialized and used throughout the component.


85-91: Improved code handling logic in renderArtifacts.

The updated logic for extracting innerText from code elements is more precise. Ensure that this change doesn't overlook any edge cases, particularly with different HTML structures.

Test with various code snippets to ensure robustness.


148-154: Integration of ReloadButtonIcon in PreCode is effective.

The reload button enhances the user interface by providing a clear reload option. Ensure that its positioning and functionality are intuitive for users.


194-200: Ensure show-hide-button functionality is intuitive.

The show-hide-button for toggling code visibility should be user-friendly. Ensure that the button's behavior is consistent and intuitive across different scenarios.

Consider user testing to gather feedback on the button's usability.

@lloydzhou lloydzhou requested a review from Dogtiti August 21, 2024 03:23
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 b0e9a54 and 4b9697e.

Files selected for processing (2)
  • app/components/artifacts.tsx (5 hunks)
  • app/components/markdown.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/components/artifacts.tsx
  • app/components/markdown.tsx

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 4b9697e and 3d5b211.

Files selected for processing (1)
  • app/components/artifacts.tsx (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/components/artifacts.tsx

@lloydzhou lloydzhou changed the title Hotfix/hide button Hotfix: Expand button for code block Aug 21, 2024
@lloydzhou lloydzhou merged commit ffe3269 into ChatGPTNextWeb:main Aug 21, 2024
1 of 2 checks passed
@lloydzhou lloydzhou deleted the hotfix/hide-button branch September 26, 2024 13:35
@coderabbitai coderabbitai bot mentioned this pull request Nov 12, 2024
10 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.

[Bug] html的预览咋没了
1 participant