Skip to content

[Tabs] Fix RTL scrollbar with Chrome 85#22830

Merged
oliviertassinari merged 2 commits into
mui:nextfrom
ankit:patch-scroll-left
Oct 5, 2020
Merged

[Tabs] Fix RTL scrollbar with Chrome 85#22830
oliviertassinari merged 2 commits into
mui:nextfrom
ankit:patch-scroll-left

Conversation

@ankit

@ankit ankit commented Oct 1, 2020

Copy link
Copy Markdown
Contributor

Chrome 85 introduced a bug with how scrollLeft is computed for RTL. This was fixed in the original source of this module -- alitaheri/normalize-scroll-left#6. The bug has been open for ~29 days, so not clear if it will be fixed anytime soon - https://bugs.chromium.org/p/chromium/issues/detail?id=1123301. This particular fix is backwards/forwards compatible according to the original PR.

Example of bug's impact: This bug is actually causing the RTL implementation of Scrollable Tabs to be broken in production when using a right-to-left language: https://material-ui.com/components/tabs/#scrollable-tabs

A better longterm fix would be to actually import https://github.com/alitaheri/normalize-scroll-left as a dependency, but I didn't go that route since I wasn't sure if we are deliberately trying to reduce the number of third-party dependencies.

Is master the correct branch for a bugfix for 4.11? Will it be possible to publish a 4.11.1 release including this bugfix?
I can also open a separate PR for next branch.

Thanks!

@mui-pr-bot

mui-pr-bot commented Oct 1, 2020

Copy link
Copy Markdown

Details of bundle changes

Generated by 🚫 dangerJS against ac953bb

@ankit ankit changed the title update utils/scrollLeft with patch to workaround chrome 85 bug [core] update utils/scrollLeft with patch to workaround chrome 85 bug Oct 1, 2020
@nabc

nabc commented Oct 3, 2020

Copy link
Copy Markdown

I was going to report this, but @ankit beat me to it :)
@oliviertassinari Please review !

@oliviertassinari oliviertassinari changed the title [core] update utils/scrollLeft with patch to workaround chrome 85 bug [Tabs] Workaround for Chrome 85 regression Oct 3, 2020
@oliviertassinari oliviertassinari added type: bug It doesn't behave as expected. scope: tabs Changes related to the tabs. labels Oct 3, 2020
@oliviertassinari

Copy link
Copy Markdown
Member

What do you think about this fix instead?

diff --git a/packages/material-ui/src/utils/scrollLeft.js b/packages/material-ui/src/utils/scrollLeft.js
index 2898642c4a..d336b0e4f6 100644
--- a/packages/material-ui/src/utils/scrollLeft.js
+++ b/packages/material-ui/src/utils/scrollLeft.js
@@ -18,7 +18,9 @@ export function detectScrollType() {
   }

   const dummy = document.createElement('div');
-  dummy.appendChild(document.createTextNode('ABCD'));
+  const container = document.createElement('div');
+  container.style.width = '100px';
+  container.style.height = '1px';
+  dummy.appendChild(container);
   dummy.dir = 'rtl';
   dummy.style.fontSize = '14px';
   dummy.style.width = '4px';

Is master the correct branch for a bugfix for 4.11? Will it be possible to publish a 4.11.1 release including this bugfix?

I would be leaning toward a target on the next branch. RTL has 2% of the download market share. Does it qualify for a critical bug fix? If you need it now, you can install: "@material-ui/core": "https://pkg.csb.dev/mui-org/material-ui/commit/f08eb4b7/@material-ui/core".

A better longterm fix would be to actually import https://github.com/alitaheri/normalize-scroll-left as a dependency, but I didn't go that route since I wasn't sure if we are deliberately trying to reduce the number of third-party dependencies.

I don't think that we need this dependency. The logic is getting normalized under a spec, browsers are progressively aligning:

diff --git a/packages/material-ui/src/utils/scrollLeft.js b/packages/material-ui/src/utils/scrollLeft.js
index 2898642c4a..926e2da037 100644
--- a/packages/material-ui/src/utils/scrollLeft.js
+++ b/packages/material-ui/src/utils/scrollLeft.js
@@ -6,11 +6,17 @@ let cachedType;
  *
-  * Types of scrollLeft, assiming scrollWidth=100 and direction is rtl.
+  * Types of scrollLeft, assuming scrollWidth=100 and direction is rtl.
  *
- * Browser        | Type          | <- Most Left | Most Right -> | Initial
--- a/packages/material-ui/src/utils/scrollLeft.js
+++ b/packages/material-ui/src/utils/scrollLeft.js
@@ -6,11 +6,17 @@ let cachedType;
  *
  * Types of scrollLeft, assiming scrollWidth=100 and direction is rtl.
  *
- * Browser        | Type          | <- Most Left | Most Right -> | Initial
- * -------------- | ------------- | ------------ | ------------- | -------
- * WebKit         | default       | 0            | 100           | 100
- * Firefox/Opera  | negative      | -100         | 0             | 0
- * IE/Edge        | reverse       | 100          | 0             | 0
+ * Type             | <- Most Left | Most Right -> | Initial
+ * ---------------- | ------------ | ------------- | -------
+ * default          | 0            | 100           | 100
+ * negative (spec*) | -100         | 0             | 0
+ * reverse          | 100          | 0             | 0
+ *
+ * Edge 85: default
+ * Safari 14: negative
+ * Chrome 85: negative
+ * Firefox 81: negative
+ * IE 11: reverse
+ *
+ * spec* https://drafts.csswg.org/cssom-view/#dom-window-scroll
  */

@oliviertassinari oliviertassinari changed the title [Tabs] Workaround for Chrome 85 regression [Tabs] Fix RTL scrollbar with Chrome 85 Oct 3, 2020
@oliviertassinari
oliviertassinari changed the base branch from master to next October 4, 2020 16:28
@nabc

nabc commented Oct 5, 2020

Copy link
Copy Markdown

@oliviertassinari I think your fix is cleaner and less third-party dependencies is better
as for bug fix, well I think it qualifies, because 2% of market share is still a lot of people, plus even though you provided a package that includes the fix (thanks for that!), i'm guessing it would not be updated to include the rest of the changes that will happen until the next stable version is published
but it is your decision ultimately!!

@oliviertassinari

Copy link
Copy Markdown
Member

because 2% of market share is still a lot of people

@nabc I would agree if we had an open issue about it with dozens of upvotes. It's not the case. Regarding v4, the next release will contain the deprecation messages we have done to reduce the gap between v4 and v5. But we can cherry-pick the diff to the master branch, it doesn't cost us much.

@oliviertassinari
oliviertassinari merged commit 16047fd into mui:next Oct 5, 2020
@ankit

ankit commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the quick follow up and merging.

What do you think about this fix instead?

diff --git a/packages/material-ui/src/utils/scrollLeft.js b/packages/material-ui/src/utils/scrollLeft.js
index 2898642c4a..d336b0e4f6 100644
--- a/packages/material-ui/src/utils/scrollLeft.js
+++ b/packages/material-ui/src/utils/scrollLeft.js
@@ -18,7 +18,9 @@ export function detectScrollType() {
   }

   const dummy = document.createElement('div');
-  dummy.appendChild(document.createTextNode('ABCD'));
+  const container = document.createElement('div');
+  container.style.width = '100px';
+  container.style.height = '1px';
+  dummy.appendChild(container);
   dummy.dir = 'rtl';
   dummy.style.fontSize = '14px';
   dummy.style.width = '4px';

Thanks, does look much cleaner.

Is master the correct branch for a bugfix for 4.11? Will it be possible to publish a 4.11.1 release including this bugfix?

I would be leaning toward a target on the next branch. RTL has 2% of the download market share. Does it qualify for a critical bug fix? If you need it now, you can install: "@material-ui/core": "https://pkg.csb.dev/mui-org/material-ui/commit/f08eb4b7/@material-ui/core".

Thanks for the reference to using the commit hash for the dependency, very helpful.

A better longterm fix would be to actually import https://github.com/alitaheri/normalize-scroll-left as a dependency, but I didn't go that route since I wasn't sure if we are deliberately trying to reduce the number of third-party dependencies.

I don't think that we need this dependency. The logic is getting normalized under a spec, browsers are progressively aligning:

diff --git a/packages/material-ui/src/utils/scrollLeft.js b/packages/material-ui/src/utils/scrollLeft.js
index 2898642c4a..926e2da037 100644
--- a/packages/material-ui/src/utils/scrollLeft.js
+++ b/packages/material-ui/src/utils/scrollLeft.js
@@ -6,11 +6,17 @@ let cachedType;
  *
-  * Types of scrollLeft, assiming scrollWidth=100 and direction is rtl.
+  * Types of scrollLeft, assuming scrollWidth=100 and direction is rtl.
  *
- * Browser        | Type          | <- Most Left | Most Right -> | Initial
--- a/packages/material-ui/src/utils/scrollLeft.js
+++ b/packages/material-ui/src/utils/scrollLeft.js
@@ -6,11 +6,17 @@ let cachedType;
  *
  * Types of scrollLeft, assiming scrollWidth=100 and direction is rtl.
  *
- * Browser        | Type          | <- Most Left | Most Right -> | Initial
- * -------------- | ------------- | ------------ | ------------- | -------
- * WebKit         | default       | 0            | 100           | 100
- * Firefox/Opera  | negative      | -100         | 0             | 0
- * IE/Edge        | reverse       | 100          | 0             | 0
+ * Type             | <- Most Left | Most Right -> | Initial
+ * ---------------- | ------------ | ------------- | -------
+ * default          | 0            | 100           | 100
+ * negative (spec*) | -100         | 0             | 0
+ * reverse          | 100          | 0             | 0
+ *
+ * Edge 85: default
+ * Safari 14: negative
+ * Chrome 85: negative
+ * Firefox 81: negative
+ * IE 11: reverse
+ *
+ * spec* https://drafts.csswg.org/cssom-view/#dom-window-scroll
  */

Makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tabs Changes related to the tabs. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants