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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
dist: focal
language: node_js
node_js:
- v20.13.1
cache:
directories:
- node_modules
before_install:
- npm i -g [email protected]
install:
- npm install
script:
- npm run build
16 changes: 8 additions & 8 deletions components/iframeCommunication.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ const IframeCommunication = () => {
const debounceTimeout = useRef(null);

const sendPageHeight = () => {
const pageHeight = document.documentElement.scrollHeight || document.body.scrollHeight;

// Only send if there's a meaningful difference in height
if (Math.abs(pageHeight - lastHeight.current) > 40) {
lastHeight.current = pageHeight;

// Debounce the message to avoid excessive calls
const contentHeight = document.body.offsetHeight;
console.log("Actual content height:", contentHeight);

if (Math.abs(contentHeight - lastHeight.current) > 40) {
lastHeight.current = contentHeight;

clearTimeout(debounceTimeout.current);
debounceTimeout.current = setTimeout(() => {
sendMessageToParent({ type: SupportedMessageTypes.PageHeight, height: pageHeight });
sendMessageToParent({ type: SupportedMessageTypes.PageHeight, height: contentHeight });
}, 50);
}
};


useEffect(() => {
// Send initial page height and path
Expand Down
21 changes: 17 additions & 4 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import '../styles.css'
import { useEffect } from 'react';
import '../styles.css';
import IframeCommunication from '../components/iframeCommunication';

// This default export is required in a new `pages/_app.js` file.

export default function MyApp({ Component, pageProps }) {
return <><IframeCommunication /><Component {...pageProps} /></>;
useEffect(() => {
if (window.self !== window.top) {
document.body.classList.add("in-iframe");
} else {
document.body.classList.remove("in-iframe");
}
}, []);

return (
<>
<IframeCommunication />
<Component {...pageProps} />
</>
);
}
6 changes: 5 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ body {
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica',
'Arial', sans-serif;
overflow-y: hidden;
}
}

body:not(.in-iframe) {
overflow-y: auto;
}
Loading