8000 fix: remove some IE-specific code in dom and style by rachel-fenichel · Pull Request #6396 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: remove some IE-specific code in dom and style #6396

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

Merged
merged 2 commits into from
Aug 30, 2022

Conversation

rachel-fenichel
Copy link
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Part of #6325

Proposed Changes

  • Remove some IE-specific code related to setting and reading styles.
  • Remove use of getCascadedStyle and mark it as deprecated.
  • Simplify code in getComputedStyle by using window instead of document.defaultView
    • MDN documentation on getComputedStyle says "In many code samples, getComputedStyle is used from the document.defaultView object. In nearly all cases, this is needless, as getComputedStyle exists on the window object as well. It's likely the defaultView pattern was a combination of folks not wanting to write a testing spec for window and making an API that was also usable in Java."
  • Use ?. to tighten up some style checks. There's future work here to sort out the AnyDuringMigrations and figure out whether we need to access style in a different way.

Behavior Before Change

No change in behaviour.

Behavior After Change

No change.

Reason for Changes

This code ostensibly worked in IE, but that's irrelevant since we no longer transpile to ES5.

Test Coverage

Opened the playground and clicked around in both Firefox and Chrome. Will need comprehensive testing in all browsers, along with other changes related to #6325.

Documentation

None

Additional Information

getCascadedStyle was probably not being used externally, but I'm going through the full deprecation process because of its visibility and lack of @internal marker.

@rachel-fenichel rachel-fenichel requested a review from a team as a code owner August 29, 2022 18:59
@rachel-fenichel rachel-fenichel requested review from BeksOmega and removed request for cpcallen August 29, 2022 19:01
@rachel-fenichel rachel-fenichel added type: cleanup PR: fix Fixes a bug deprecation This PR deprecates an API. labels Aug 29, 2022
// element.style[..] is undefined for browser specific styles
// as 'filter'.
return (styles as AnyDuringMigration)[property] ||
styles.getPropertyValue(property) || '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
styles.getPropertyValue(property) || '';
styles.getPropertyValue(property);

@@ -109,17 +106,11 @@ function getStyle(element: Element, style: string): string {
* @alias Blockly.utils.style.getComputedStyle
*/
export function getComputedStyle(element: Element, property: string): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this exported but getStyle is not? Do we want to deprecate this and then stop exporting it in v10?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't delete it because we use it in flyout_button.ts, but I can deprecate it and leave myself a note to make it @internal instead of deleting it in the next release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I don't like that because it means we have deprecation warnings in the browser for normal things (flyouts with buttons) for a full release.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we export getStyle instead, and use that? (since it seems like the more general-purpose function anyway)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But then we're just dropping one export to add another, which I don't like.

I'm looking into the uses of getStyle to see when one or the other gets used and whether I can simplify more.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We ended up deleting getStyle since element.getComputedStyle returns a superset of the values on element.style, so the function would always short circuit before reaching the ||. I.e. it wasn't doing anything different from getComputedStyle.

@rachel-fenichel rachel-fenichel merged commit a785ab8 into google:develop Aug 30, 2022
@rachel-fenichel rachel-fenichel deleted the remove_ie_style branch August 30, 2022 19:49
@rachel-fenichel
Copy link
Collaborator Author

Testing: before release, this should be tested in firefox in an iframe that starts hidden.

@@ -134,6 +106,9 @@ export function getComputedStyle(element: Element, property: string): string {
* @alias Blockly.utils.style.getCascadedStyle
*/
export function getCascadedStyle(element: Element, style: string): string {
deprecation.warn(
'Blockly.utils.style.getCascadedStyle', 'version 9.0.0',
'version 10.0.0');
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this clear approach, but I note that it doesn't makie any promises about how long the deprecated function will be available for. For example, though unlikely it's not inconceivable that a serious security bug could force a major version bump the day after 9.0 is release.

Given that:

  • we don't think this is used externally, and
  • we're not obliged to remove deprecated features

I think that's fine, but perhaps be careful about adopting this style more generally until we are reasonably sure we can set and stick to a schedule for major version bumps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This PR deprecates an API. PR: fix Fixes a bug type: cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0