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

Embed form flickering bug #658

Merged
merged 2 commits into from
Jan 3, 2025
Merged

Embed form flickering bug #658

merged 2 commits into from
Jan 3, 2025

Conversation

chiragchhatrala
Copy link
Collaborator

@chiragchhatrala chiragchhatrala commented Jan 2, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Improved dark mode handling across the application
    • Enhanced dynamic HTML class management for forms
  • Bug Fixes

    • Added safer property access for form configurations
    • Prevented potential runtime errors with optional chaining
  • Improvements

    • Streamlined dark mode application to the root document element
    • Optimized form visibility and class rendering logic

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request focuses on refining the dark mode functionality across the client-side codebase. The changes primarily involve updating how dark mode is applied by consistently targeting the document's root element (document.documentElement) instead of the body element. Modifications enhance the robustness of dark mode handling in both the form library and form page components, introducing safer property access and more dynamic class management.

Changes

File Change Summary
client/lib/forms/public-page.js Updated dark mode functions to use document.documentElement instead of document.body, ensuring consistent root-level dark mode application.
client/pages/forms/[slug]/index.vue Added getHtmlClass computed property, improved dark mode and visibility handling with optional chaining and dynamic class management.

Possibly related PRs

  • 1390d dark mode issues #450: The changes in this PR address dark mode styling in various components, which is directly related to the modifications made in the main PR regarding the handling of dark mode functionality in public-page.js.

Suggested reviewers

  • JhumanJ

Poem

🌓 Dark Mode Dance 🌓
In the realm of pixels bright,
Root elements now take flight,
Classes toggle with such grace,
Dark and light in seamless embrace!
🐰 - CodeRabbit's Styling Bard


📜 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 fde2215 and 286de7a.

📒 Files selected for processing (1)
  • client/pages/forms/[slug]/index.vue (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/pages/forms/[slug]/index.vue

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
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 (2)
client/lib/forms/public-page.js (1)

86-86: Graceful Fallback for Dark Mode Check
The nullish coalescing (??) expression is well-chosen. It ensures that if elem.value is not defined, the logic still correctly falls back to document.documentElement.

Consider adding an early return or additional guards if finalElement is not present, to safeguard against uninitialized states in certain SSR or hydration edge cases.

client/pages/forms/[slug]/index.vue (1)

162-166: Duplicate Visibility Logic in onMounted
The same code block removing the 'hidden' class occurs again in onMounted. While it clarifies the logic flow, ensure you truly need to call it both times. If not, consider consolidating or extracting into a shared routine to avoid potential confusion or duplication.

- nextTick(() => {
-   document.documentElement.classList.remove('hidden')
- })
...
- nextTick(() => {
-   document.documentElement.classList.remove('hidden')
- })
+ function removeHiddenClass() {
+   nextTick(() => document.documentElement.classList.remove('hidden'))
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2366f95 and fde2215.

📒 Files selected for processing (2)
  • client/lib/forms/public-page.js (5 hunks)
  • client/pages/forms/[slug]/index.vue (4 hunks)
🔇 Additional comments (9)
client/lib/forms/public-page.js (4)

1-1: Use of document.documentElement for Dark Mode is Well-Advised
Shifting the dark mode parent from document.body to document.documentElement ensures the styling is applied across the entire page rather than just the body element. This helps avoid partial or inconsistent styling in various edge cases.


10-10: Ensure elem Validity Before Assigning
Assigning darkModeNodeParent to elem ?? document.documentElement is sound. However, if elem is not a valid HTML element, it might introduce subtle behavior. Ensure that calls to handleDarkMode pass a valid HTML element or null.


69-69: Refined effectiveElem Computation
Relying on document.documentElement rather than document.body is consistent and more future-proof. Good alignment with the process.client check ensures this code only runs on the client side.


133-134: Consistent Removal of 'dark' Class
Removing the 'dark' class directly from document.documentElement is consistent with the refactor. This ensures a complete switch back to light mode without potential orphan 'dark' classes lingering.

client/pages/forms/[slug]/index.vue (5)

139-140: Dark & Transparent Mode Handling
Calling handleDarkMode and handleTransparentMode with the form values centralizes the mode logic. This is consistent with the adjustments made in public-page.js.


142-145: Fixing Flicker by Removing 'hidden' Class
Your approach to remove the 'hidden' class from document.documentElement after loading addresses potential flickering issues. This ensures the content becomes visible once relevant data is loaded.


250-256: Reactive HTML Class Computation
Using a computed property getHtmlClass to conditionally set dark and hidden classes is a clean approach that aligns well with Vue’s reactivity model. This helps reduce direct DOM manipulation.


259-261: Dynamic HTML Attributes
Applying dynamic attributes (dir, class, lang) based on the form’s properties is a good pattern, offering flexibility for i18n and theme handling.


281-281: Script Injection for iFrame Resizing
Adding iframeResizer.contentWindow.min.js is useful if the form is hosted in an iframe. Ensure that the resource is always available or handle potential network issues gracefully.

@JhumanJ JhumanJ merged commit 09c4417 into main Jan 3, 2025
5 checks passed
@JhumanJ JhumanJ deleted the 73679-embed-form-flickering-bug branch January 3, 2025 15:03
@coderabbitai coderabbitai bot mentioned this pull request Jan 3, 2025
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