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

Revert back the full page scroll logic + fix infinite scroll updates #45

Merged
merged 4 commits into from
Feb 11, 2025

Conversation

bobbykolev
Copy link
Collaborator

@bobbykolev bobbykolev commented Feb 11, 2025

  • apply the body class logic only when not in an iFrame;
  • remove the redundant styles;
  • version bump

Summary by CodeRabbit

  • Chores

    • Updated the application version for improved maintenance and tracking.
  • Refactor

    • Streamlined the logic responsible for iframe detection and error handling, enhancing reliability.
  • Style

    • Simplified layout and overflow management by adopting a cleaner, class-based approach, resulting in a more consistent display.
  • Enhancements

    • Improved debugging output with additional logging for scroll height changes in iframe communication.

Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

This pull request updates the project's package version from 0.1.0 to 0.1.1. It modifies the iframe detection logic in the main application component by removing the server environment check and applying a simplified try-catch block to add a "not-in-iframe" class when the window is at the top level. Additionally, global CSS rules and selectors related to iframe scenarios have been removed and updated to rely on class-based overflow management. A new constant for height difference threshold is introduced in the iframe communication logic.

Changes

File(s) Change Summary
package.json Updated version from "0.1.0" to "0.1.1".
pages/_app.js Modified useEffect hook for iframe detection: removed server check, simplified error handling, and now adds "not-in-iframe" class when applicable.
styles.css Removed global CSS rules for html and body, deleted iframe-related styles, and updated selectors to apply overflow management via classes.
components/iframeCommunication.js Introduced constant HEIGHT_DIFFERENCE_THRESHOLD set to 130, replacing hardcoded value, and added console logs for debugging scroll height changes.

Possibly related PRs

Suggested reviewers

  • reactoholic
  • DonnaDuiker

Poem

I'm a bunny with eyes so bright,
Hopping through code both day and night.
With version bumps and style reset,
I cheer the changes—no regret!
Hop along, let bugs take flight! 🐰✨


📜 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 a76c3cd and e05556b.

📒 Files selected for processing (1)
  • components/iframeCommunication.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/iframeCommunication.js
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: Travis CI - Pull Request
  • GitHub Check: Travis CI - Branch

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

🧹 Nitpick comments (1)
pages/_app.js (1)

7-11: Consider adding error logging in catch block.

The empty catch block silently suppresses errors, which could make debugging difficult in production.

    try {
      if (window.self === window.top) {
        document.body.classList.add("not-in-iframe");
      }
-    } catch (e) {}
+    } catch (e) {
+      console.warn('Failed to determine iframe status:', e);
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61019f2 and 131c09b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • pages/_app.js (1 hunks)
  • styles.css (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • package.json
  • styles.css
🔇 Additional comments (2)
pages/_app.js (2)

1-4: LGTM! Component structure follows Next.js best practices.

The component maintains a clean structure with proper imports and follows the standard Next.js _app.js patterns.

Also applies to: 14-20


6-12: Verify the scroll behavior in different contexts.

Please ensure that:

  1. Scrolling works correctly when the page is loaded directly (not in iframe)
  2. Scrolling behavior is appropriate when loaded within an iframe
  3. The transition between states doesn't cause layout shifts
✅ Verification successful

🌐 Web query:

What are the best practices for handling page scrolling in iframes with Next.js?

💡 Result:

When implementing iframes with controlled scrolling behavior in Next.js applications, developers should combine HTML attributes, CSS styling, and framework-specific optimizations while prioritizing security and performance:

Scrollbar Control & Overflow Management

  • Use scrolling="no" attribute combined with overflow:hidden CSS
<iframe src="/widget" scrolling="no" style={{overflow:'hidden'}} />

This hides both vertical/horizontal scrollbars[2][5][7]. For targeted control:

.no-scroll-iframe { overflow: hidden }

Security Hardening

  1. Apply sandbox restrictions:
<iframe sandbox="allow-scripts allow-same-origin" />
  1. Configure CSP headers in next.config.js:
headers: [{
  source: '/(.*)',
  headers: [
    { key: 'Content-Security-Policy', value: "frame-src 'self' https://trusted-domains.com" }
  ]
}]

[4][6]

Performance Optimization

  • Implement lazy loading:
<iframe loading="lazy" />
  • Use dynamic imports for heavy iframes:
const DynamicIframe = dynamic(() => import('@/components/Iframe'), {
  ssr: false,
  loading: () => <SkeletonLoader />
})

[3][4]

Responsive Behavior
Create aspect-ratio containers:

.iframe-container {
  position: relative;
  padding-top: 56.25%; /* 16:9 */
}

.iframe-container iframe {
  position: absolute;
  top:0;
  left:0;
  width:100%;
  height:100%;
}

[4][7]

Client-Side Workarounds
For cases where SSR strips attributes:

useEffect(() => {
  document.querySelectorAll('iframe').forEach(iframe => {
    iframe.setAttribute('scrolling', 'no')
  })
}, [])

[2][5]

Cross-Origin Communication
Safe message handling:

useEffect(() => {
  window.addEventListener('message', handleIframeMessage)
  return () => window.removeEventListener('message', handleIframeMessage)
}, [])

const handleIframeMessage = (e) => {
  if(e.origin !== 'https://trusted-source.com') return
  // Process message
}

[4][6]

For complex scroll interactions combining iframes with page animations, consider integrating scroll libraries like Lenis through wrapper components while maintaining isolated iframe scroll contexts[1][8]. Always test across browsers and provide fallbacks for motion-sensitive users[4][7].

Citations:


Scroll Behavior Verification: Confirming Context-Sensitive Styling

The changes in pages/_app.js now add the "not-in-iframe" class when the page is loaded directly, which aligns with the PR objective of reverting full-page scroll logic and removing redundant styles. Based on current best practices for handling iframes in Next.js, please ensure that:

  • When loaded directly, the presence of "not-in-iframe" triggers the intended scroll behavior.
  • In an iframe, the absence of "not-in-iframe" prevents the application of full page scroll styles.
  • Transitioning between these states does not lead to any layout shifts.

Manual testing in both contexts is recommended to confirm that scrolling and layout behave as expected.

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

43-58: Consider implementing structured debugging and monitoring.

Given the complexity of iframe height management and the need for debugging, consider implementing:

  1. A proper logging/monitoring strategy using a logging library
  2. Performance metrics collection for height changes
  3. Error boundaries to catch and report issues

This will provide better insights into production issues without relying on console logs.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 131c09b and a76c3cd.

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

4-4: LGTM! Good improvement in code maintainability.

Extracting the magic number into a named constant improves code readability and maintainability.


48-48: LGTM! Clean usage of the new constant.

The threshold check is now more maintainable using the named constant.

@bobbykolev bobbykolev changed the title Revert back the full page scroll logic Revert back the full page scroll logic + fix infinite scroll updates Feb 11, 2025
@DonnaDuiker DonnaDuiker merged commit a5b266f into develop Feb 11, 2025
6 checks passed
@DonnaDuiker DonnaDuiker deleted the fix-scroll branch February 11, 2025 14:27
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