Skip to content

BREAKING CHANGE: Encapsulate Popper API#22586

Merged
spmonahan merged 21 commits into
microsoft:9.0-breaking-changesfrom
ling1726:feat/popper-api-refactor
May 20, 2022
Merged

BREAKING CHANGE: Encapsulate Popper API#22586
spmonahan merged 21 commits into
microsoft:9.0-breaking-changesfrom
ling1726:feat/popper-api-refactor

Conversation

@ling1726

@ling1726 ling1726 commented Apr 21, 2022

Copy link
Copy Markdown
Contributor

⚠️ BREAKING CHANGES

Offset array -> Offset object

Use the same API as Floating UI

Before

<Popover positioning={{ offset: [0, 10] }} />

After

<>
  <Popover positioning={{ offset: { crossAxis: 0, mainAxis: 10 } }} />
  {/* main axis shorthand */}
  <Popover positioning={{ offset: 10 }} />
</>

Offset function argument

Stops using third party library naming and concepts in the offset function. Instead of using Popper placement, uses position and align concepts from the library:

Before

export type OffsetFunctionParam = {
  popper: Rect;
  reference: Rect;
  placement: Placement;
};

After

export type OffsetFunctionParam = {
  positionedElement: Rect;
  target: Rect;
  position: Position;
  alignment: Alignment;
};

PopperVirtualElement -> PositioningVirtualElement

Follows the Floating UI virtual element type. The only difference is that x & y are now required.

TS playground with example

popperRef -> positioningRef

Removes Popper instances from our API

Before

type PopperRefHandle = {
  updatePosition: () => void;
  setTarget: (target: HTMLElement | PositioningVirtualElement) => void;
};

<Popover positioning={{ popperRef }} />;

After

type PositioningRefHandle = {
  updatePosition: () => void;
  setTarget: (target: HTMLElement | PositioningVirtualElement) => void;
};
<Popover positioning={{ positioningRef }} />;

PopperVirtualElement -> PositioningVirtualElement

Type was renamed.


Fixes #22585

Updates `@fluentui/react-positioning` so that none of the popper API and
types leak anymore
@codesandbox-ci

codesandbox-ci Bot commented Apr 21, 2022

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d5505bf:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@fabricteam

fabricteam commented Apr 21, 2022

Copy link
Copy Markdown
Collaborator

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-combobox
Combobox
60.792 kB
20.778 kB
61.406 kB
20.981 kB
614 B
203 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
180.24 kB
50.256 kB
180.903 kB
50.469 kB
663 B
213 B
react-menu
Menu (including children components)
110.243 kB
33.543 kB
110.869 kB
33.746 kB
626 B
203 B
react-menu
Menu (including selectable components)
113.418 kB
34.011 kB
114.044 kB
34.213 kB
626 B
202 B
react-popover
Popover
101.158 kB
30.817 kB
101.821 kB
31.067 kB
663 B
250 B
react-positioning
usePositioning
23.21 kB
8.084 kB
23.828 kB
8.283 kB
618 B
199 B
react-tooltip
Tooltip
42.939 kB
14.782 kB
43.598 kB
14.994 kB
659 B
212 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-avatar
Avatar
45.608 kB
13.312 kB
react-components
react-components: FluentProvider & webLightTheme
34.078 kB
11.098 kB
🤖 This report was generated against 51777323141411ce197a6314e211c326af180c60

@fabricteam

fabricteam commented Apr 21, 2022

Copy link
Copy Markdown
Collaborator

Perf Analysis (@fluentui/react-components)

Scenario Render type Master Ticks PR Ticks Iterations Status
FluentProviderWithTheme mount 388 384 10 Possible regression
FluentProviderWithTheme virtual-rerender 359 346 10 Possible regression
FluentProviderWithTheme virtual-rerender-with-unmount 405 428 10 Possible regression
All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1265 1249 5000
Button mount 760 793 5000
FluentProvider mount 2305 2375 5000
FluentProviderWithTheme mount 388 384 10 Possible regression
FluentProviderWithTheme virtual-rerender 359 346 10 Possible regression
FluentProviderWithTheme virtual-rerender-with-unmount 405 428 10 Possible regression
MakeStyles mount 2031 1980 50000

@size-auditor

size-auditor Bot commented Apr 21, 2022

Copy link
Copy Markdown

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 51777323141411ce197a6314e211c326af180c60 (build)

@ling1726 ling1726 marked this pull request as ready for review April 21, 2022 18:10
@ling1726 ling1726 requested review from a team, behowell, khmakoto and smhigley as code owners April 21, 2022 18:10
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "BREAKING CHANGE: Encapsulate Popper API",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"comment": "BREAKING CHANGE: Encapsulate Popper API",
"comment": "BREAKING: Rename types and APIs to avoid references to third party API",

?

positionedElement: Rect;
target: Rect;
position: Position;
alignment?: Alignment;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it really optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, by default our alignment is center

Comment thread packages/react-positioning/src/types.ts Outdated
Comment thread packages/react-positioning/src/useMouseTarget.ts Outdated
Comment thread packages/react-positioning/src/utils/fromPopperPlacement.test.ts Outdated
Comment thread packages/react-positioning/src/utils/getPopperOffset.test.ts Outdated
Comment thread packages/react-positioning/src/utils/getPopperOffset.test.ts Outdated
Comment thread packages/react-positioning/src/utils/getPopperOffset.test.ts
Comment thread packages/react-positioning/src/utils/getPopperOffset.test.ts Outdated
Comment thread packages/react-positioning/src/utils/getPopperOffset.ts Outdated

@spmonahan spmonahan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just putting a block here so we can coordinate merging breaking changes.

@spmonahan spmonahan changed the base branch from master to 9.0-breaking-changes May 19, 2022 19:25

@behowell behowell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The react-combobox and react-tooltip changes look good, just a few nitpicks. I only skimmed the rest.

Comment thread packages/react-components/react-combobox/src/components/Combobox/useCombobox.ts Outdated
Comment thread packages/react-components/react-tooltip/src/components/Tooltip/useTooltip.tsx Outdated
@@ -55,7 +55,7 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLBu
const popperOptions = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(nit) rename popperOptions to positioningOptions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto in other places that have a local popperOptions or popperState

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

makes sense done in d5505bf

@spmonahan spmonahan changed the base branch from 9.0-breaking-changes to master May 20, 2022 01:22
export type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';

export type PopperRefHandle = {
export type PositioningImperativeRef = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Consider PositioningRef. Is the word imperative necessary? Aren't all ref's imperative? :) Do you think there will be other kinds of positioning refs that we'll need to distinguish between?

position: 'below' as const,
align: 'start' as const,
offset: [0, 2] as Offset,
offset: 2,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this change be to use the crossAxis, mainAxis offset instead of the single number?


export type { PositioningProps, PositioningShorthand, PositioningShorthandValue } from '@fluentui/react-positioning';
export type {
PositioningProps,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you also want to export the types used within these types such as Offset, Alignment, Position?

import * as PopperJs from '@popperjs/core';
import * as React from 'react';

type Rect = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider if you DOMRect would be a good structure to use here. It has x, y, width, and height, but also top, left, right, and bottom. It can be annoying to create instances of a DOMRect because of the fromRect method, but might fit well with positioning.

*/
export function parsePopperPlacement(placement: Placement): { basePlacement: BasePlacement; alignment: Variation } {
const tokens = placement.split('-');
return {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any way that the placement could be malformed and not have 2 tokens? If so, consider a check here to either throw a specific error, provide a default, or return null.

['top', undefined, 'above'],
['bottom', undefined, 'below'],
['left', undefined, 'before'],
['right', undefined, 'after'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider adding invalid input tests.

[
[0, 0],
[0, 1],
{ crossAxis: 0, mainAxis: 0 },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can offsets be negative? What is the expected result if they are?

offset[1] += arrowHeight;
} else {
offset[1] = arrowHeight;
const addArrowOffset = (offset: OffsetObject | number, arrowHeight: number): OffsetObject => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: While typescript will handle it, it is generally better js practice to always put method declarations before you use them when possible.

@spmonahan spmonahan changed the base branch from master to 9.0-breaking-changes May 20, 2022 18:24
@spmonahan spmonahan merged commit 968737e into microsoft:9.0-breaking-changes May 20, 2022
spmonahan pushed a commit that referenced this pull request May 21, 2022
* BREAKING CHANGE: Encapsulate Popper API

Updates `@fluentui/react-positioning` so that none of the popper API and
types leak anymore

* changefiles

* update test

* update stories

* positioned to positionedElement

* update api

* remove getBasePlacement

* add tests

* virtual element and boundary

* fix types

* PR fixes

* update md

* fix type

* changefile

* Update packages/react-components/react-combobox/src/components/Combobox/useCombobox.ts

Co-authored-by: Ben Howell <[email protected]>

* Update packages/react-components/react-tooltip/src/components/Tooltip/useTooltip.tsx

Co-authored-by: Ben Howell <[email protected]>

* rename popperOptions to positioningOptions

Co-authored-by: Ben Howell <[email protected]>
spmonahan added a commit that referenced this pull request May 23, 2022
* react-button: Removing deprecated block prop from all button components (#23071)

* react-button: Removing deprecated block prop from all button components.

* Removing block stories.

* Adding changefile.

* Removing block prop from migration guide and vr tests.

* fix(react-text): Update typography wrappers to latest naming (#22934)

* fix: change Headline to Subtitle1

* fix: change Subheadline to Subtitle2

* fix: change Body to Body1

* fix: change Caption to Caption1

* feat: add Caption2

* chore: use better vr story name

* chore: add change files

* chore: update api

* fix: rename components in missing story

* feat: removed unused `caption2ClassName`

* chore: disable classname conformance test

* chore: remove deprecated className

* chore: add conformance test exception

* BREAKING: Removing deprecated `<componentName>ClassName` exports from v9 packages (#23026)

* removing single static classnames

* api files

* change files

* disabling component-has-static-classname-exported test in react-image

* preparing to merge master

* disabling export tests

* removing change file for text

* change file

* disabling test in Dialog

* disabling more tests

* remove react-text class names

Co-authored-by: Sean Monahan <[email protected]>

* BREAKING: Update string unions to `spinal-case` (#23001)

* react-avatar: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-input: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-radio: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-select: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-spinbutton: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-tabster: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-textarea: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-badge: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* react-combobox: update unions to use spinal-case

BREAKING

Per #22596 all string
unions are being updated to use spinal-case

* add change files for spinal-case update

* react-card: update tabster tab behaviors

Updates the `useCard()` implementation after the `react-tabster`
spinal-case breaking change.

* vr-tests: update types for v9 tests

* react-avatar: update badge types in stories

Avatar stories were using the old, camelCase PresenceBadge types.

* react-badge: fix style that broke with spinal-case change

One of the "doNotDisturb" cases was missed due to the non-typesafe way
we tested the PresenceBadge status in styles.

This test has been changed to a typesafe function call instead.

* react-combobox: update props in appearance story

Change filledDarker and filledLighter to filled-darker and filled-lighter
respectively.

* react-badge: update camelCase to spinal-case for strings

* fix: missing inputClassName in merge conflict resolution

* react-select: update api snapshot

* react-alert: update conformance tests

* fix: update react-components api snapshot

* BREAKING CHANGE: Encapsulate Popper API (#22586)

* BREAKING CHANGE: Encapsulate Popper API

Updates `@fluentui/react-positioning` so that none of the popper API and
types leak anymore

* changefiles

* update test

* update stories

* positioned to positionedElement

* update api

* remove getBasePlacement

* add tests

* virtual element and boundary

* fix types

* PR fixes

* update md

* fix type

* changefile

* Update packages/react-components/react-combobox/src/components/Combobox/useCombobox.ts

Co-authored-by: Ben Howell <[email protected]>

* Update packages/react-components/react-tooltip/src/components/Tooltip/useTooltip.tsx

Co-authored-by: Ben Howell <[email protected]>

* rename popperOptions to positioningOptions

Co-authored-by: Ben Howell <[email protected]>

* BREAKING: Remove context exports from react-components (#23085)

* BREAKING: Remove context exports from react-components

In order to provider proper encapsulation and allow us to change
internals more easily, this PR removes exports of context objects from
react-components. In cases where contexts were removed, the export was
replaced with a specific provider component and hook to use the context
value.

Follows from #22300

* changefile

* stop exporting menu contexts

* changefile

* update md

Co-authored-by: Sean Monahan <[email protected]>

* react-popover: update api snapshot

* BREAKING(react-theme): remove webHighContrastTheme (#23083)

* fix(react-theme): Remove webHighContrast theme

Co-authored-by: Makoto Morimoto <[email protected]>
Co-authored-by: André Dias (he/him) <[email protected]>
Co-authored-by: Esteban Munoz Facusse <[email protected]>
Co-authored-by: ling1726 <[email protected]>
Co-authored-by: Ben Howell <[email protected]>
Co-authored-by: Miroslav Stastny <[email protected]>
marwan38 pushed a commit to marwan38/fluentui that referenced this pull request Jun 13, 2022
* react-button: Removing deprecated block prop from all button components (microsoft#23071)

* react-button: Removing deprecated block prop from all button components.

* Removing block stories.

* Adding changefile.

* Removing block prop from migration guide and vr tests.

* fix(react-text): Update typography wrappers to latest naming (microsoft#22934)

* fix: change Headline to Subtitle1

* fix: change Subheadline to Subtitle2

* fix: change Body to Body1

* fix: change Caption to Caption1

* feat: add Caption2

* chore: use better vr story name

* chore: add change files

* chore: update api

* fix: rename components in missing story

* feat: removed unused `caption2ClassName`

* chore: disable classname conformance test

* chore: remove deprecated className

* chore: add conformance test exception

* BREAKING: Removing deprecated `<componentName>ClassName` exports from v9 packages (microsoft#23026)

* removing single static classnames

* api files

* change files

* disabling component-has-static-classname-exported test in react-image

* preparing to merge master

* disabling export tests

* removing change file for text

* change file

* disabling test in Dialog

* disabling more tests

* remove react-text class names

Co-authored-by: Sean Monahan <[email protected]>

* BREAKING: Update string unions to `spinal-case` (microsoft#23001)

* react-avatar: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-input: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-radio: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-select: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-spinbutton: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-tabster: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-textarea: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-badge: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* react-combobox: update unions to use spinal-case

BREAKING

Per microsoft#22596 all string
unions are being updated to use spinal-case

* add change files for spinal-case update

* react-card: update tabster tab behaviors

Updates the `useCard()` implementation after the `react-tabster`
spinal-case breaking change.

* vr-tests: update types for v9 tests

* react-avatar: update badge types in stories

Avatar stories were using the old, camelCase PresenceBadge types.

* react-badge: fix style that broke with spinal-case change

One of the "doNotDisturb" cases was missed due to the non-typesafe way
we tested the PresenceBadge status in styles.

This test has been changed to a typesafe function call instead.

* react-combobox: update props in appearance story

Change filledDarker and filledLighter to filled-darker and filled-lighter
respectively.

* react-badge: update camelCase to spinal-case for strings

* fix: missing inputClassName in merge conflict resolution

* react-select: update api snapshot

* react-alert: update conformance tests

* fix: update react-components api snapshot

* BREAKING CHANGE: Encapsulate Popper API (microsoft#22586)

* BREAKING CHANGE: Encapsulate Popper API

Updates `@fluentui/react-positioning` so that none of the popper API and
types leak anymore

* changefiles

* update test

* update stories

* positioned to positionedElement

* update api

* remove getBasePlacement

* add tests

* virtual element and boundary

* fix types

* PR fixes

* update md

* fix type

* changefile

* Update packages/react-components/react-combobox/src/components/Combobox/useCombobox.ts

Co-authored-by: Ben Howell <[email protected]>

* Update packages/react-components/react-tooltip/src/components/Tooltip/useTooltip.tsx

Co-authored-by: Ben Howell <[email protected]>

* rename popperOptions to positioningOptions

Co-authored-by: Ben Howell <[email protected]>

* BREAKING: Remove context exports from react-components (microsoft#23085)

* BREAKING: Remove context exports from react-components

In order to provider proper encapsulation and allow us to change
internals more easily, this PR removes exports of context objects from
react-components. In cases where contexts were removed, the export was
replaced with a specific provider component and hook to use the context
value.

Follows from microsoft#22300

* changefile

* stop exporting menu contexts

* changefile

* update md

Co-authored-by: Sean Monahan <[email protected]>

* react-popover: update api snapshot

* BREAKING(react-theme): remove webHighContrastTheme (microsoft#23083)

* fix(react-theme): Remove webHighContrast theme

Co-authored-by: Makoto Morimoto <[email protected]>
Co-authored-by: André Dias (he/him) <[email protected]>
Co-authored-by: Esteban Munoz Facusse <[email protected]>
Co-authored-by: ling1726 <[email protected]>
Co-authored-by: Ben Howell <[email protected]>
Co-authored-by: Miroslav Stastny <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Floating UI breaking changes

8 participants