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

Fix : Hydration error by improving the HTML Specifications #482

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Rustix69
Copy link

@Rustix69 Rustix69 commented Feb 14, 2025

Fixes #473

Describe the changes you have made in this PR -

  • Updated the HTML specifications such that it will not lead to Hydration Errors.

Screenshots of the changes

image

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit

  • Refactor

    • Improved context menu behavior by simplifying lifecycle management.
    • Enhanced properties panels on both desktop and mobile for quicker, dynamic updates as state changes occur.
  • Style

    • Updated the table layout in the Testbench Panel to improve clarity and accessibility with better semantic structure.
    • Refined input group spacing and layout for a cleaner, more consistent visual presentation.

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request makes several minor yet focused modifications. A newline character is removed in the project’s package.json. The ContextMenu component is simplified by removing the mounted lifecycle hook. Both desktop and mobile versions of the PropertiesPanel transition from a polling mechanism to a reactive approach using watchers. Additionally, semantic improvements are applied to Extra.vue with the introduction of <thead> and <tbody>, and InputGroups.vue is updated for better styling and layout control.

Changes

File(s) Change Summary
package.json Removed an unnecessary newline at the end of the file.
src/components/ContextMenu/ContextMenu.vue Removed the mounted lifecycle hook that called hideContextMenu.
src/components/Panels/PropertiesPanel/PropertiesPanel.vue
src/components/Panels/PropertiesPanelMobile.vue
Removed setInterval for showPropertiesPanel; updated onMounted to call showPropertiesPanel directly; added a watcher in mobile version for propertiesPanelStore.titleEnable.
v0/src/components/Extra.vue
v0/src/components/Panels/Shared/InputGroups.vue
Improved HTML markup: Extra.vue now uses <thead> and <tbody> for a semantic table structure, while InputGroups.vue replaces a <p> tag with a <div> for better styling and layout control.

Possibly related PRs

  • Combining Vue Simulator Versioning PRs #337: The changes in the main PR, which involve a minor modification to the package.json file, are related to the retrieved PR that also modifies the package.json file by changing the build command and adding a new dependency.

Suggested labels

GSOC'24

Poem

I’m a rabbit in the code burrow, hoppin’ with glee,
Watching panels update reactively so seamlessly.
ContextMenu now hides with a simpler flow,
And tables in Extra are structured to show.
A whimsical tweak in each vue file’s format,
Hop along, dear coder, and admire where we’re at!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fdb020 and a093cb3.

📒 Files selected for processing (3)
  • src/components/ContextMenu/ContextMenu.vue (1 hunks)
  • src/components/Panels/PropertiesPanel/PropertiesPanel.vue (1 hunks)
  • src/components/Panels/PropertiesPanel/PropertiesPanelMobile.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Panels/PropertiesPanel/PropertiesPanel.vue
  • src/components/Panels/PropertiesPanel/PropertiesPanelMobile.vue
🔇 Additional comments (2)
src/components/ContextMenu/ContextMenu.vue (2)

46-48: LGTM! Removing the mounted hook improves hydration.

The removal of the mounted hook is a good change as it eliminates client-side only behavior. Instead, ensure the initial state is set correctly in the data function.


58-79: ⚠️ Potential issue

Address potential issues in menu item click handler.

Several concerns in the click handler:

  1. document.execCommand() is deprecated for clipboard operations.
  2. globalScope is used without type checking or import.
  3. String comparison uses == instead of ===.
         menuItemClicked(event) {
             this.hideContextMenu()
-            const id = event.target.dataset.index
+            const id = parseInt(event.target.dataset.index ?? '0')
             
-            if (id == 0) {
+            if (id === 0) {
-                document.execCommand('copy')
+                navigator.clipboard.writeText(/* your content */)
-            } else if (id == 1) {
+            } else if (id === 1) {
-                document.execCommand('cut')
+                navigator.clipboard.writeText(/* your content */)
+                // Then delete content
-            } else if (id == 2) {
+            } else if (id === 2) {
                 paste(localStorage.getItem('clipboardData'))
-            } else if (id == 3) {
+            } else if (id === 3) {
                 deleteSelected()
-            } else if (id == 4) {
+            } else if (id === 4) {
                 undo()
-            } else if (id == 5) {
+            } else if (id === 5) {
                 createNewCircuitScope()
-            } else if (id == 6) {
+            } else if (id === 6) {
                 logixFunction.createSubCircuitPrompt()
-            } else if (id == 7) {
+            } else if (id === 7) {
+                if (typeof globalScope !== 'undefined') {
                     globalScope.centerFocus(false)
+                }
             }
         },

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

netlify bot commented Feb 14, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit a093cb3
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/67af92fe87b8570008da9f86
😎 Deploy Preview https://deploy-preview-482--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (3)
src/components/Panels/PropertiesPanel/PropertiesPanel.vue (1)

25-36: Consider optimizing watch options.

The deep watch might be unnecessary for primitive values like panelType and inLayoutMode. Consider using an array of separate watchers for better performance:

-watch(
-    () => [
-        propertiesPanelStore.panelType,
-        propertiesPanelStore.inLayoutMode,
-        propertiesPanelStore.propertiesPanelObj
-    ],
-    () => {
-        showPropertiesPanel()
-    },
-    { deep: true }
-)
+// Watch primitive values without deep option
+watch([
+    () => propertiesPanelStore.panelType,
+    () => propertiesPanelStore.inLayoutMode
+], () => {
+    showPropertiesPanel()
+})
+
+// Watch complex object with deep option
+watch(
+    () => propertiesPanelStore.propertiesPanelObj,
+    () => {
+        showPropertiesPanel()
+    },
+    { deep: true }
+)
src/components/Panels/PropertiesPanel/PropertiesPanelMobile.vue (1)

175-187: Consider optimizing the panel state watcher.

While the current implementation works, consider these optimizations:

  1. Split into separate watchers for independent properties to avoid unnecessary updates
  2. Remove deep: true if deep watching isn't required for all properties

Example refactor:

-// Watch for properties panel state changes
-watch(
-    () => [
-        propertiesPanelStore.panelType,
-        propertiesPanelStore.inLayoutMode,
-        propertiesPanelStore.propertiesPanelObj,
-        simulatorMobileStore.showPropertiesPanel
-    ],
-    () => {
-        showPropertiesPanel()
-    },
-    { deep: true }
-)
+// Watch panel type and mode
+watch(
+    [
+        () => propertiesPanelStore.panelType,
+        () => propertiesPanelStore.inLayoutMode,
+        () => simulatorMobileStore.showPropertiesPanel
+    ],
+    () => {
+        showPropertiesPanel()
+    }
+)
+
+// Watch properties panel object with deep watching
+watch(
+    () => propertiesPanelStore.propertiesPanelObj,
+    () => {
+        showPropertiesPanel()
+    },
+    { deep: true }
+)
src/components/ContextMenu/ContextMenu.vue (1)

2-2: Consider improvements to template bindings.

  1. Replace oncontextmenu="return false;" with @contextmenu.prevent for better Vue idioms.
  2. Using array indices as keys might cause issues with Vue's virtual DOM diffing when items are reordered.
-    <div id="contextMenu" oncontextmenu="return false;" :class="{ hidden: !isVisible }">
+    <div id="contextMenu" @contextmenu.prevent :class="{ hidden: !isVisible }">
         <ul>
             <li
                 v-for="(menuOption, index) in contextMenuOptions"
-                :key="index"
+                :key="menuOption"
                 :data-index="index"
                 @click="menuItemClicked($event)"
             >

Also applies to: 4-12

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea73f2 and 7fdb020.

📒 Files selected for processing (6)
  • package.json (1 hunks)
  • src/components/ContextMenu/ContextMenu.vue (2 hunks)
  • src/components/Panels/PropertiesPanel/PropertiesPanel.vue (1 hunks)
  • src/components/Panels/PropertiesPanel/PropertiesPanelMobile.vue (2 hunks)
  • v0/src/components/Extra.vue (1 hunks)
  • v0/src/components/Panels/Shared/InputGroups.vue (3 hunks)
✅ Files skipped from review due to trivial changes (3)
  • v0/src/components/Panels/Shared/InputGroups.vue
  • v0/src/components/Extra.vue
  • package.json
🔇 Additional comments (7)
src/components/Panels/PropertiesPanel/PropertiesPanel.vue (2)

1-9: LGTM! Clean template structure with proper prop passing.

The template follows Vue best practices with appropriate use of toRaw for the properties panel object to prevent proxy-related issues.


14-18: LGTM! Clean imports and store initialization.

The transition from polling to a reactive approach using Vue's composition API is a significant improvement.

src/components/Panels/PropertiesPanel/PropertiesPanelMobile.vue (3)

144-144: LGTM: Import changes align with the new reactive approach.

The addition of the watch import from 'vue' supports the transition from polling to a reactive approach.


161-165: LGTM: Improved initialization with immediate panel display.

The addition of showPropertiesPanel() in onMounted ensures proper initialization without relying on polling, which is a more efficient approach.


167-173: LGTM: Clean implementation of title enable watcher.

The watcher is well-focused and correctly handles title enable state changes.

src/components/ContextMenu/ContextMenu.vue (2)

16-23: LGTM! Clean setup with TypeScript.

The script setup syntax is properly used, and imports are well-organized.


83-93: LGTM! Clean transition implementation.

The transitions are well-defined and properly scoped to the component.

src/components/ContextMenu/ContextMenu.vue Outdated Show resolved Hide resolved
src/components/ContextMenu/ContextMenu.vue Outdated Show resolved Hide resolved
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 Specifications are not being followed which can lead to Hydration Errors.
1 participant