From 3eaf5e67fd945f4ffdfa0b95767ef5508f9dd33c Mon Sep 17 00:00:00 2001 From: Joe Gregory Date: Wed, 5 Jan 2022 12:11:36 -0800 Subject: [PATCH] fix: prevent auto-scroll for I/O --- gatsby-browser.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gatsby-browser.js b/gatsby-browser.js index c66e4533d..a973fa435 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -55,4 +55,27 @@ const onClientEntry = () => { window.ReactDOM = require('react-dom'); }; -export { wrapPageElement, onInitialClientRender, onClientEntry }; +const shouldUpdateScroll = ({ routerProps: { location } }) => { + const PAGE_OFFSET_HEIGHT = 575; + const IS_IO = location.pathname.includes('instant-observability'); + + // scrolls only after search query parameter on I/O site changes + if (IS_IO && location.search) { + window.setTimeout(() => + window.scrollTo({ top: PAGE_OFFSET_HEIGHT, left: 0, behavior: 'smooth' }) + ); + + // Does not update to default behavior to persist this change + return false; + } + + // if we're not on I/O, update to default behavior + return true; +}; + +export { + wrapPageElement, + onInitialClientRender, + onClientEntry, + shouldUpdateScroll, +};