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

enable scrolling locally, but keep disabled in iframe #43

Merged
merged 9 commits into from
Feb 7, 2025

Conversation

DonnaDuiker
Copy link
Contributor

@DonnaDuiker DonnaDuiker commented Feb 6, 2025

Describe the background of your pull request

What does your pull request do? Does it solve a bug (which one?), add a feature?

Additional context

Add any other context

Governance

  • Documentation is added
  • Test cases are added or updated

By submitting this pull request I confirm that:

Summary by CodeRabbit

  • New Features

    • The application now automatically detects if it is viewed within an embedded frame, adjusting the interface accordingly.
  • Style

    • Enhanced scrolling behavior by enabling auto scrolling when the page is not viewed inside a frame.
    • Improved layout with new styling rules for the main content area and iframe.
  • Chores

    • Updated Travis CI configuration to optimize build processes and dependency management.
  • Bug Fixes

    • Improved height calculation for content sent to the parent window in the iframe communication.

Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Walkthrough

This update introduces a new control flow in the application root. In pages/_app.js, a useEffect hook determines whether the app is running in an iframe and updates the document body class accordingly. In styles.css, new rules adjust the overflow behavior based on the presence of the .in-iframe class. The main component rendering remains unchanged. Additionally, the Travis CI configuration is updated to optimize the build process.

Changes

Files Change Summary
pages/_app.js Added a useEffect hook that checks if the window is an iframe. Depending on the context, it adds or removes the in-iframe class to/from the document body.
styles.css Introduced new CSS rules for html and body elements to set height and overflow properties. Added rule: body:not(.in-iframe) { overflow-y: auto; }.
.travis.yml Configured Travis CI to use Node.js 20.13.1 with focal distribution, added npm version 10.5.0 installation, and defined build and install steps.
components/iframeCommunication.js Modified sendPageHeight function to use document.body.offsetHeight for height calculation and improved debugging output.

Possibly related PRs

Suggested reviewers

  • reactoholic

Poem

Oh, hop! I'm a bunny on the run,
Coding through iframe fun,
Adding classes with a swift little skip,
Adjusting scrolls before your eyes can grip,
With changes in code, I dance with glee —
A little digital hop for you and me!
🐇✨


📜 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 78d7c4f and fed738a.

📒 Files selected for processing (1)
  • styles.css (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: Travis CI - Pull Request
  • GitHub Check: Travis CI - Branch
🔇 Additional comments (7)
styles.css (7)

1-5: Review Base Styles for html, body
The rules set a fixed height (100vh) and a maximum height (100vh) while disabling overflow on both the html and body elements. This creates a strict baseline layout that relies on later rules for scroll control. Consider reviewing if using a fixed height may cause issues on mobile devices with dynamic viewport sizes.


7-11: Base Body Rule and Default Overflow Setting
The base body rule applies a font-family and sets overflow-y: hidden. This default, combined with the earlier html/body rule, ensures that scrolling is initially disabled and is later conditionally enabled. Please confirm that this cascade produces the intended behavior in both local and iframe contexts.


13-15: Enabling Local Scrolling
The selector body:not(.in-iframe) explicitly sets overflow-y: auto for local contexts (when the body does not have the .in-iframe class). This correctly enables vertical scrolling when not embedded.


17-24: Main Content Container Settings
The .main-content class is defined as a flex container with height restrictions and overflow-y: auto, ensuring that its contents can scroll. This is useful when content overflows. As a suggestion, consider if employing min-height (instead of a strict height: 100%) might improve responsiveness for variable content lengths.


26-31: iFrame Layout and Scrolling Behavior
The iframe selector forces the iframe to span the full viewport height with height: 100vh !important and enables vertical scrolling via overflow-y: auto !important. While this ensures the iframe content is not clipped, please evaluate if the use of !important is necessary here, as it may override other cascading styles unexpectedly.


33-37: ⚠️ Potential issue

iFrame Override for Body Element
The body.in-iframe rule applies overflow-y: auto !important and adjusts height properties when the app is rendered in an iframe. However, the PR title indicates that scrolling should remain disabled in an iframe. If the objective is to prevent scrolling when embedded, this rule should likely set overflow-y: hidden instead. Please double-check the intended behavior in the iframe context.


39-43: ⚠️ Potential issue

iFrame Override for Main Content
Within an iframe context, the .main-content rule under body.in-iframe enforces overflow-y: auto !important, which enables scrolling of the main content. This appears inconsistent with the PR objective "keep disabled in iframe" (assuming that means full-page scrolling should remain disabled). Clarify whether scrollability should be allowed on inner containers in the iframe or if it must be entirely disabled, and adjust the overflow property accordingly.


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.

@DonnaDuiker DonnaDuiker requested a review from hero101 February 6, 2025 13:50
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4dc209 and 5efd8a3.

📒 Files selected for processing (2)
  • pages/_app.js (1 hunks)
  • styles.css (1 hunks)
🔇 Additional comments (2)
pages/_app.js (1)

14-19: LGTM! Clean component structure maintained.

The component structure is clean and the return statement properly renders both the IframeCommunication component and the main Component with its props.

styles.css (1)

7-9: LGTM! CSS implementation aligns with PR objective.

The CSS implementation correctly:

  • Uses the :not pseudo-class for clean selector logic
  • Maintains hidden overflow in iframe context
  • Enables scrolling in local context

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)
components/iframeCommunication.js (1)

45-45: Consider making the height difference threshold configurable.

The 40-pixel threshold for sending height updates seems arbitrary. Consider making it a configurable constant or prop to allow adjustment based on different use cases.

+const HEIGHT_UPDATE_THRESHOLD = 40; // pixels
+
 const IframeCommunication = () => {
     const router = useRouter();
     const lastHeight = useRef(0);
     const debounceTimeout = useRef(null);

     const sendPageHeight = () => {
         const contentHeight = document.body.offsetHeight;
         if (process.env.NODE_ENV === 'development') {
             console.log("Actual content height:", contentHeight);
         }
    
-        if (Math.abs(contentHeight - lastHeight.current) > 40) {
+        if (Math.abs(contentHeight - lastHeight.current) > HEIGHT_UPDATE_THRESHOLD) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e5f382a and c2b61d7.

📒 Files selected for processing (1)
  • components/iframeCommunication.js (1 hunks)
🔇 Additional comments (2)
components/iframeCommunication.js (2)

54-54: Formatting change noted.


41-43: Verify height calculation behavior with hidden content.

The change from scrollHeight to offsetHeight might not account for content that's hidden due to overflow. Please verify this change doesn't cause issues with:

  1. Dynamic content loading
  2. Expandable sections
  3. Long content that should be scrollable

Additionally, consider wrapping the debug log in a development check:

-        console.log("Actual content height:", contentHeight);
+        if (process.env.NODE_ENV === 'development') {
+            console.log("Actual content height:", contentHeight);
+        }

@DonnaDuiker DonnaDuiker requested review from hero101 and removed request for hero101 February 7, 2025 13:25
@hero101 hero101 merged commit 61019f2 into develop Feb 7, 2025
6 checks passed
@hero101 hero101 deleted the enable-scrolling branch February 7, 2025 13:44
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