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

CSS: Fix support test results for initially hidden iframes #5317

Merged
merged 6 commits into from
Nov 2, 2023

Conversation

ssigwart
Copy link

@ssigwart ssigwart commented Sep 12, 2023

Summary

If the iframe is not initially visible, boxSizingReliableVal gets set to false, which triggers this code to set the wrong dialog width here:

jquery/src/css.js

Lines 418 to 426 in a7cc3a0

if ( isBorderBox && scrollboxSizeBuggy ) {
subtract -= Math.ceil(
elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
parseFloat( styles[ dimension ] ) -
boxModelAdjustment( elem, dimension, "border", false, styles ) -
0.5
);
}

I think this should solve jquery/jquery-ui#2176.

You can reproduce something similar to the original issue by creating the following two files in the top level of a website. Then go to index.html, click "Show Frame", then "Show Popup". The popup should be 600px, but is not.

index.html

<!DOCTYPE html>
<html>
	<body>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.js" integrity="sha512-+k1pnlgt4F1H8L7t3z95o3/KO+o78INEcXTbnoJQ/F2VqDVhWoaiVml/OEHv9HsVgxUaVW+IbiZPUJQfF/YxZw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.js" integrity="sha512-ynDTbjF5rUHsWBjz7nsljrrSWqLTPJaORzSe5aGCFxOigRZRmwM05y+kuCtxaoCSzVGB1Ky3XeRZsDhbSLdzXQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<div hidden="hidden" id="testFrame">
			<iframe src="/innerIframe.html" style="width: 100%; height: 500px"></iframe>
		</div>
		<button type="button" onclick="$('#testFrame').prop('hidden', false);this.hidden=true;">Show Frame</button>
	</body>
</html>

innerIframe.html

<!DOCTYPE html>
<html>
	<head>
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css" integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
		<style>
			* {
				box-sizing: border-box;
			}
			.ui-dialog {
				width: 400px;
			}
		</style>
	</head>
	<body>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.js" integrity="sha512-+k1pnlgt4F1H8L7t3z95o3/KO+o78INEcXTbnoJQ/F2VqDVhWoaiVml/OEHv9HsVgxUaVW+IbiZPUJQfF/YxZw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.js" integrity="sha512-ynDTbjF5rUHsWBjz7nsljrrSWqLTPJaORzSe5aGCFxOigRZRmwM05y+kuCtxaoCSzVGB1Ky3XeRZsDhbSLdzXQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<div id="testPopup" hidden="hidden" style="width: 800px;">
			Popup
		</div>
		<button type="button" onclick="$('#testPopup').dialog({width: 600});">Show Popup</button>
		<script>
			// Calling this triggers `computeStyleTests` to be called before the page is visible
			console.log($('#testPopup').outerHeight());
		</script>
	</body>
</html>

Checklist

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. We will need a unit test added for a change like that. This one would go to https://github.com/jquery/jquery/blob/main/test/unit/css.js.

@mgol mgol added 3.x-only and removed Needs info labels Sep 20, 2023
@ssigwart
Copy link
Author

Thanks, @mgol. I added a test and verified that it failed prior to my change.

@mgol mgol added Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Sep 21, 2023
@mgol mgol added this to the 3.7.2 milestone Sep 21, 2023
@@ -18,6 +18,11 @@ define( [
return;
}

// Don't run until window is visible (https://github.com/jquery/jquery-ui/issues/2176)
if ( documentElement.offsetHeight === 0 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be true if height: 0 is set on the root element in CSS. We may need a better check.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any suggestions? I'm not sure what the rational for setting height: 0 on the root element would be.

Maybe I can have it check if the width is zero too. I didn't test that yet. I wanted to get your thoughts on that first.

Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather check against div directly than against its containing document and assuming accuracy and correspondence. Specifically, I think div.offsetWidth would be a good target: https://jsfiddle.net/tjnvs51o/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to div.offsetWidth. It think it works, though I'm struggling to figure out how to run all the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple ways to run tests:

  1. With npm scripts: npm run browser. This will run tests on the command line using karma and headless browsers. Set the browser you want with the BROWSERS env var. See Gruntfile.cjs.
  2. Open the QUnit test page directly and run the test using the QUnit UI. Run node test/server.js and visit http://localhost:3000/test/. Your test is in the support module so select that from the module list to filter the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test in this PR is failing in Safari. Also, we want to remove the test container element before the early return.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timmywil we should document this in README.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning on documenting all of the upcoming test changes (to drop grunt, karma, etc). node test/server.js will likely be added to an npm script.

test/unit/css.js Outdated
"css/cssComputeStyleTests.html",
function( assert, jQuery, window, document, initialHeight ) {
assert.expect( 2 );
assert.strictEqual( initialHeight, 0, "initial height should be undefined" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Safari actually is reporting offsetHeight for the div in the hidden iframe: https://github.com/jquery/jquery/actions/runs/6634909917/job/18189746921?pr=5317#step:9:161

Suggested change
assert.strictEqual( initialHeight, 0, "initial height should be undefined" );
assert.strictEqual( initialHeight === 0 ? 20 : initialHeight, 20,
"hidden-frame content sizes should be zero or accurate" );

@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Oct 30, 2023
@ssigwart
Copy link
Author

ssigwart commented Nov 1, 2023

I made the suggested updates. I haven't really been able to get the tests running well. I might be running them wrong. The way I'm running them, it's failing on 3.x-stable too. Also, npm run browser failed with Missing script: "browser" and I don't see a test/server.js file.

@mgol
Copy link
Member

mgol commented Nov 1, 2023

@ssigwart you need to rebase over latest 3.x-stable. And the command should actually be npm run test:browser.

@ssigwart
Copy link
Author

ssigwart commented Nov 1, 2023

Thanks, @mgol. I'll try to do that tonight. I try not to rebase after people have started reviewing so it doesn't mess up their review.

@mgol
Copy link
Member

mgol commented Nov 1, 2023

Also, there’s a bug in Chrome 117 & 118 that causes one support test failure. The issue is fixed in Chrome 119 so we’re just waiting for GitHub Actions images to be updated with Chrome 119 to resolve this one failure.

@ssigwart
Copy link
Author

ssigwart commented Nov 2, 2023

Thanks. I rebased and force pushed that. Running npm run test:browser worked. There was one failure, but that was on Chrome 118. Is there anything else you need me to do on this PR?

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! LGTM.

@mgol mgol changed the title Fix UI Dialog Width for Initially Hidden Dialog CSS: Fix support test results for initially hidden iframes Nov 2, 2023
@mgol mgol merged commit ac68b21 into jquery:3.x-stable Nov 2, 2023
6 of 11 checks passed
@mgol mgol removed the Needs review label Nov 2, 2023
@ssigwart ssigwart deleted the narrowDialog branch November 2, 2023 12:32
@ssigwart
Copy link
Author

ssigwart commented Nov 2, 2023

Thanks for your help and merging this.

mgol added a commit to mgol/jquery that referenced this pull request Nov 3, 2023
Also, account for the fact old Firefox (<61) has `null` computed style
for elements in such iframes.

Ref jquerygh-5317
mgol added a commit to mgol/jquery that referenced this pull request Nov 3, 2023
mgol added a commit to mgol/jquery that referenced this pull request Nov 3, 2023
Also, account for the fact old Firefox (<61) has `null` computed style
for elements in such iframes.

Ref jquerygh-5317
@mgol
Copy link
Member

mgol commented Nov 3, 2023

I submitted two followups to this PR, to apply the fix to the reliableTrDimensions support test as well.

mgol added a commit that referenced this pull request Nov 6, 2023
Also, account for the fact old Firefox (<61) has `null` computed style
for elements in such iframes.

Closes gh-5359
Ref gh-5317
Ref gh-5358
mgol added a commit that referenced this pull request Nov 13, 2023
Old iOS (<10) always rounds widths down, account for this in tests.

Closes gh-5361
Ref gh-5317
Ref gh-5359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants