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 Invalid HTML Structure to Prevent Vue Hydration Errors #475

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

Conversation

gitsofaryan
Copy link
Contributor

@gitsofaryan gitsofaryan commented Feb 12, 2025

Fixes ##473

Describe the changes you have made in this PR -

  • Fixed <tr> as a child of :

    Before: You had a <tr> (table row) directly inside a <table>, but possibly not inside a <tbody>, <thead>, or <tfoot>.
    Fix: You wrapped the <tr> inside a <tbody>, which is required by HTML specifications.

    • Fixed
      inside <p> issue:

    Before: You had a <div> inside a <p>, which is invalid because <p> cannot contain block-level elements like

    .
    Fix: You likely replaced the <p> with a <span> (which can contain inline elements) or moved the <div> outside the <p>.

    Screenshots of the changes (If any) -

    • no html structure errors
    • image

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

    Summary by CodeRabbit

    • Refactor

      • Enhanced the semantic structure of the Testbench Panel in the Extra component.
      • Improved user input controls in the InputGroups component for better reactivity and validation.
    • Tests

      • Introduced an automated testing workflow to continuously ensure application stability and performance.

Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

This update adjusts the HTML in the Testbench Panel by wrapping table row elements in a <tbody> in one component, refactors template and script logic in another component to better utilize Vue’s composition API and improve numeric processing, and introduces a new GitHub Actions workflow for running simulator tests. The changes focus on improved semantics, reactivity, and automated testing without altering public APIs.

Changes

File(s) Change Summary
v0/src/components/Extra.vue Wrapped existing <tr> elements for "Bitwidth", "Current Case", and "Result" within a <tbody> tag, enhancing semantic HTML structure.
v0/src/components/Panels/Shared/InputGroups.vue Removed the <p> tag in favor of a <div>, updated event handlers to reference methods directly, refactored functions to use ref and Vue Composition API, and modified props to accept both strings and numbers.
.github/workflows/tests.yml Added a new GitHub Actions workflow that checks out the repository, sets up Node.js, installs packages, and runs simulator tests.

Suggested Reviewers

  • Arnabdaz

Poem

I'm a rabbit, hopping by with cheer,
Code changes fresh and crystal clear.
Tables now wrapped with proper care,
Inputs refined with updated flair.
Tests run in a workflow so neat,
Hopping along with a joyful beat!
🐇✨


🪧 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.
  • @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 12, 2025

Deploy Preview for circuitverse ready!

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

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 48
Accessibility: 72
Best Practices: 92
SEO: 80
PWA: -
View the detailed breakdown and full score reports

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

🧹 Nitpick comments (2)
v0/src/components/Panels/Shared/InputGroups.vue (2)

21-22: Consider moving type conversion to computed properties.

While explicit Number() conversion in template bindings works, it's generally better to handle type conversion in computed properties for better reusability and testing.

<template>
  <input
-    :min="Number(valueMin)"
-    :max="Number(valueMax)"
+    :min="minValue"
+    :max="maxValue"
    ...
  />
</template>

<script setup lang="ts">
+ import { computed } from 'vue';
  ...
+ const minValue = computed(() => Number(props.valueMin));
+ const maxValue = computed(() => Number(props.valueMax));
</script>

62-72: Enhance type safety in value manipulation methods.

The increase/decrease methods could benefit from stronger type safety and shared validation logic.

+ function validateValue(value: number): number {
+    const min = Number(props.valueMin);
+    const max = Number(props.valueMax);
+    return Math.min(Math.max(value, min), max);
+ }

 function increaseValue() {
     if (!inputRef.value) return;
     let value = Number(inputRef.value.value) || 0;
     const step = Number(props.stepSize) || 1;
-    const max = Number(props.valueMax);
-
-    if (value + step <= max) {
-        value += step;
-        emit("update:propertyValue", value);
-    }
+    value = validateValue(value + step);
+    emit("update:propertyValue", value);
 }

 function decreaseValue() {
     if (!inputRef.value) return;
     let value = Number(inputRef.value.value) || 0;
     const step = Number(props.stepSize) || 1;
-    const min = Number(props.valueMin);
-
-    if (value - step >= min) {
-        value -= step;
-        emit("update:propertyValue", value);
-    }
+    value = validateValue(value - step);
+    emit("update:propertyValue", value);
 }

Also applies to: 74-84

📜 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 a60a908.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • v0/src/components/Extra.vue (1 hunks)
  • v0/src/components/Panels/Shared/InputGroups.vue (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • v0/src/components/Extra.vue
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - circuitverse
  • GitHub Check: Header rules - circuitverse
  • GitHub Check: Pages changed - circuitverse
🔇 Additional comments (3)
v0/src/components/Panels/Shared/InputGroups.vue (3)

2-2: LGTM! HTML structure fix implemented correctly.

The replacement of <p> with <div> resolves the invalid HTML structure issue mentioned in the PR objectives.


10-10: LGTM! Event handler syntax improved.

The simplified event handler syntax (@click="decreaseValue" instead of @click="decreaseValue()") follows Vue best practices by avoiding unnecessary method invocation syntax.

Also applies to: 31-31


47-49: LGTM! Improved prop type flexibility.

The updated prop types now correctly accept both String and Number values, making the component more flexible while maintaining type safety through TypeScript.

@gitsofaryan
Copy link
Contributor Author

@vedant-jain03 @Arnabdaz please review changes.

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

🧹 Nitpick comments (3)
v0/src/components/Panels/Shared/InputGroups.vue (3)

4-13: Consider using more precise types and numeric defaults.

While the union types [String, Number] provide flexibility, they might lead to type coercion issues. Consider:

  1. Using numeric defaults for numeric values
  2. Using a more reasonable max value to prevent precision issues
 const props = defineProps({
     propertyName: { type: String, default: "Property Name" },
     propertyValue: { type: Number, default: 0 },
     propertyValueType: { type: String, default: "number" },
-    valueMin: { type: [String, Number], default: "0" },
-    valueMax: { type: [String, Number], default: "100000000000000" },
-    stepSize: { type: [String, Number], default: "1" },
+    valueMin: { type: [String, Number], default: 0 },
+    valueMax: { type: [String, Number], default: 1000000 },
+    stepSize: { type: [String, Number], default: 1 },
     propertyInputName: { type: String, default: "Property_Input_Name" },
     propertyInputId: { type: String, default: "Property_Input_Id" },
 });

15-16: Enhance type safety for emits and refs.

Consider adding TypeScript types for emitted events and ref value.

-const emit = defineEmits(["update:propertyValue"]);
+const emit = defineEmits<{
+  (e: 'update:propertyValue', value: number): void
+}>();

37-59: Consider consolidating validation logic.

The increase/decrease methods could benefit from reusing the validation logic from updateValue.

 function increaseValue() {
     if (!inputRef.value) return;
     let value = Number(inputRef.value.value) || 0;
     const step = Number(props.stepSize) || 1;
-    const max = Number(props.valueMax);
+    const newValue = value + step;
-    if (value + step <= max) {
-        value += step;
-        emit("update:propertyValue", value);
-    }
+    // Reuse validation logic
+    const event = { target: { value: String(newValue) } };
+    updateValue(event);
 }

 function decreaseValue() {
     if (!inputRef.value) return;
     let value = Number(inputRef.value.value) || 0;
     const step = Number(props.stepSize) || 1;
-    const min = Number(props.valueMin);
+    const newValue = value - step;
-    if (value - step >= min) {
-        value -= step;
-        emit("update:propertyValue", value);
-    }
+    // Reuse validation logic
+    const event = { target: { value: String(newValue) } };
+    updateValue(event);
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a60a908 and 694aa31.

📒 Files selected for processing (1)
  • v0/src/components/Panels/Shared/InputGroups.vue (1 hunks)
🔇 Additional comments (2)
v0/src/components/Panels/Shared/InputGroups.vue (2)

1-3: LGTM! Clean imports using Vue 3 Composition API.

The imports are well-organized and follow Vue 3 best practices by explicitly importing required composition API utilities.


18-35: Input validation implementation looks good!

The implementation now properly validates input values and handles edge cases.

Copy link
Contributor

@aryanndwi123 aryanndwi123 left a comment

Choose a reason for hiding this comment

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

LGTM 👍
@Arnabdaz

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

🧹 Nitpick comments (1)
.github/workflows/simulator-test.yml (1)

13-32: Well-Structured Job and Steps

The job run-simulator-tests is clearly structured with the following logical steps:

  • Checkout Repository using actions/checkout@v4
  • Setup Node.js with version 22 via actions/setup-node@v4
  • Install Dependencies using npm ci
  • Run Simulator Tests via npm run test -- src/simulator/spec

Each step is clearly defined and in the correct order. As a good-to-have improvement, consider adding caching (for example, caching the npm modules) to potentially speed up subsequent runs.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 694aa31 and e7eefdd.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • .github/workflows/simulator-test.yml (1 hunks)
🔇 Additional comments (2)
.github/workflows/simulator-test.yml (2)

1-2: Clear Workflow Name Defined

The workflow is named "Simulator Tests," which clearly indicates its purpose in running simulator tests.


3-12: Properly Defined Trigger Events

The on block correctly specifies triggers for both push and pull_request events on the main and dev branches. This setup ensures that the workflow runs in the appropriate scenarios to catch issues early.

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

🧹 Nitpick comments (3)
.github/workflows/tests.yml (3)

3-11: Trigger Configuration and Trailing Whitespace Cleanup

The "on" configuration correctly triggers the workflow on pushes and pull requests to the main branch. However, static analysis flagged a trailing whitespace on line 11. Please remove the extra spaces to comply with YAML style guidelines. For example:

-      - main␣␣
+      - main
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 11-11: trailing spaces

(trailing-spaces)


13-16: Job Definition Review

The job is properly defined with runs-on: ubuntu-latest for leveraging the latest Ubuntu runner. For reproducibility, consider pinning to a specific Ubuntu release if your project requires consistent environments.


29-31: Simulator Test Execution and Failure Handling

The command used for running simulator tests is:

npm run test -- src/simulator/spec || echo "Simulator tests failed"

Using || echo "Simulator tests failed" may inadvertently mask failures by allowing the step to succeed even if tests fail. Please confirm if this behavior is intended. If failing tests should exit with a non-zero status to fail the workflow, consider removing the || echo "Simulator tests failed" portion, for example:

-          npm run test -- src/simulator/spec || echo "Simulator tests failed"
+          npm run test -- src/simulator/spec
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf3517 and d5b1313.

📒 Files selected for processing (1)
  • .github/workflows/tests.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/tests.yml

[error] 11-11: trailing spaces

(trailing-spaces)

🔇 Additional comments (4)
.github/workflows/tests.yml (4)

1-2: Workflow Naming is Clear

The workflow is named "Simulator Tests," which clearly indicates its purpose for running simulator tests.


17-20: Repository Checkout Step

The checkout step uses actions/checkout@v4, which is correctly implemented to obtain the repository code.


21-25: Node.js Setup is Correct

The setup for Node.js using actions/setup-node@v4 with node-version: 20.x is properly configured. This ensures that the workflow uses a recent version of Node.js.


26-28: Dependencies Installation Step

The step to install dependencies with npm install is standard and appropriately placed before running the tests.

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