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

www.pressurecookrecipes.com - see bug description #111086

Closed
joeadops opened this issue Sep 20, 2022 — with webcompat-app · 6 comments
Closed

www.pressurecookrecipes.com - see bug description #111086

joeadops opened this issue Sep 20, 2022 — with webcompat-app · 6 comments
Labels
browser-safari os-ios Issues only happening on iOS.
Milestone

Comments

@joeadops
Copy link

URL: https://www.pressurecookrecipes.com/instant-pot-spaghetti-sauce/

Browser / Version: Safari 15+
Operating System: iOS 15+
Tested Another Browser: Yes Firefox

Problem type: Something else
Description: Page scrolls to anchor when updating a style element via ECMAScript and a link element was dynamically added on DOMContentReady
Steps to Reproduce:
The page provided (https://jrivera-projects.s3.amazonaws.com/safari-bug/index.html) has code that causes the issue and is interactive. This is a minimal test case but we have seen the problem occurring on several real world sites. One of them is: https://www.pressurecookrecipes.com/instant-pot-mushroom-risotto/#recipe where if you scroll up to the top from the recipe it'll jump back down to the recipe.

From the test case linked above: Click on "Go to element #foo" to scroll the page down to the #foo element. Then manually scroll back up here and click on the "Will it jump?" button to see the page scroll back to the #foo element. That scrolling is the issue - the page should NOT scroll. The button here is simply modify a <style> element. There are three seemingly unrelated preconditions that, when present on a page together, trigger this behavior:

PRECONDITION 1: Anchors The first is the presence of an anchor or "fragment identifier" in the URL. The fragment identifier must reference, by id, one of the elements on the page.

PRECONDITION 2: Dynamically Inserted Link Tag The second piece of the puzzle is that we need to dynamically add a element to the DOM. In order to trigger this issue, appending of the element must happen either via the "DOMContentLoaded" event or in the "readystatechange" event when document.readyState === 'interactive'. If the is added when document.readyState === 'complete', there will be NO jump. The contents of the file referenced by the href attribute don't matter. As seen in the demo here, the file could even be a 404 and the issue will manifest. Only if the "href" attribute is omitted will the issue not occur. <script type='text/javascript'> // document.addEventListener('DOMContentLoaded', () => { document.addEventListener('readystatechange', () => { if (document.readyState !== 'interactive') { return; } const link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.media = 'all'; link.property = 'stylesheet'; link.href = 'not-even-a-file.css'; document.body.appendChild(link); }); </script>

PRECONDITION 3: Dynamically Updating <Style> Tag For the final part, we simply construct a <style> element with document.createElement('style'); and add some CSS to it as a child "textNode". The actual CSS properties we specify don't seem to matter. I tested with font-size, color, and width but for this demo I leave any style properties empty. The CSS selector also does not need to match any element that is actually in the DOM! Each time the <style> element is updated, the page will jump to the element whose id is in the fragment. <script type='text/javascript'> const head = document.head || document.getElementsByTagName("head")[0]; const styleElement = document.createElement('style'); styleElement.type = "text/css"; head.appendChild(styleElement); const jumpBtn = document.querySelector('#jump'); jumpBtn.addEventListener('click', () => { const css = '#matches-nothing-in-dom {}'; const cssNode = document.createTextNode(css); const childNodes = styleElement.childNodes; const child = childNodes[0]; if (child) { styleElement.replaceChild(cssNode, child); } else { styleElement.appendChild(cssNode); } }); </script>

https://bugs.webkit.org/show_bug.cgi?id=244895

Browser Configuration
  • None

From webcompat.com with ❤️

@webcompat-bot webcompat-bot added this to the needstriage milestone Sep 20, 2022
@softvision-raul-bucata softvision-raul-bucata added os-mac Issues only happening on macOS. os-ios Issues only happening on iOS. and removed os-mac Issues only happening on macOS. labels Sep 21, 2022
@softvision-raul-bucata
Copy link

softvision-raul-bucata commented Sep 21, 2022

@joeadops Thanks for the report.
@karlcow Can we close this a duplicate of https://bugs.webkit.org/show_bug.cgi?id=244895 , as I can see some diagnosis has been done there?

Notes:
Without the preconditions, the page presents no issues when scrolling.

Tested with:

Browser/Version: Safari 15.5
Operating System: iOS 15.5

[qa_38/2022]

@dmarti
Copy link

dmarti commented Sep 21, 2022

Hi @softvision-raul-bucata, I'm trying to find the possible duplicate you mention but I'm not finding any other issues for that site. Do you have an issue number?

@softvision-raul-bucata
Copy link

@dmarti Sorry about that, I was referring to the already submitted bug in webkit: https://bugs.webkit.org/show_bug.cgi?id=244895

[inv_38/2022]

@softvision-raul-bucata
Copy link

ping @karlcow

[inv_39/2022]

@karlcow
Copy link
Member

karlcow commented Sep 30, 2022

@softvision-raul-bucata Yes we can. Thanks!

@karlcow karlcow closed this as completed Sep 30, 2022
@karlcow karlcow removed the status-needsinfo-karlcow ping @karlcow label Sep 30, 2022
@karlcow karlcow modified the milestones: needstriage, duplicate Sep 30, 2022
@karlcow
Copy link
Member

karlcow commented Sep 30, 2022

I added myself there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser-safari os-ios Issues only happening on iOS.
Projects
None yet
Development

No branches or pull requests

5 participants