Skip to content

Commit b6009b7

Browse files
[wb1812.1.deprecate] Mark ID stuff as deprecated (#2388)
## Summary: This is the first step in removing our custom ID utilities in favour of using the `useId` hook from React's API. This PR is not going to be merged/released on its own. Another PR will be coming to add an `Id` component that wraps `useId` so that there's an easier path for consumers to migrate. The difficult bit is moving from the provider architecture that gives an ID factory, to the `useId`/`Id` approach. However, long term, it should simplify things greatly. ### Upgrade note: Upgrading to this will cause deprecation notices in consuming code. If a lint rule is set up to block deprecated usage (which it probably is), then those errors will have to be suppressed. A find/replace may help in some circumstances, but this may also be a manual process. The alternative, of course, is to actually modify stuff to the new approach. Issue: WB-1812 ## Test plan: `yarn test` `yarn lint` Author: somewhatabstract Reviewers: jandrade Required Reviewers: Approved By: jandrade Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ⏭️ Chromatic - Skip on Release PR (changesets), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ⏭️ dependabot Pull Request URL: #2388
1 parent 2dbeb1d commit b6009b7

File tree

32 files changed

+68
-0
lines changed

32 files changed

+68
-0
lines changed

.changeset/light-goats-serve.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@khanacademy/wonder-blocks-core": major
3+
"@khanacademy/wonder-blocks-search-field": patch
4+
"@khanacademy/wonder-blocks-accordion": patch
5+
"@khanacademy/wonder-blocks-dropdown": patch
6+
"@khanacademy/wonder-blocks-popover": patch
7+
"@khanacademy/wonder-blocks-testing": patch
8+
"@khanacademy/wonder-blocks-tooltip": patch
9+
"@khanacademy/wonder-blocks-switch": patch
10+
"@khanacademy/wonder-blocks-modal": patch
11+
"@khanacademy/wonder-blocks-form": patch
12+
---
13+
14+
Deprecate the ID provider and unique ID utilities

__docs__/wonder-blocks-core/id-provider.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23
import type {Meta, StoryObj} from "@storybook/react";
34

__docs__/wonder-blocks-core/unique-id-provider.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23
import type {Meta, StoryObj} from "@storybook/react";
34

__docs__/wonder-blocks-core/use-unique-id.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23

34
import {Meta} from "@storybook/react";

__docs__/wonder-blocks-timing/with-action-scheduler.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23
import {Meta} from "@storybook/react";
34
import {IDProvider, View} from "@khanacademy/wonder-blocks-core";

packages/wonder-blocks-accordion/src/components/accordion-section.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from "react";
22
import {StyleSheet} from "aphrodite";
33
import type {StyleDeclaration} from "aphrodite";
44

5+
// eslint-disable-next-line import/no-deprecated
56
import {useUniqueIdWithMock, View} from "@khanacademy/wonder-blocks-core";
67
import * as tokens from "@khanacademy/wonder-blocks-tokens";
78
import {Body} from "@khanacademy/wonder-blocks-typography";
@@ -203,6 +204,7 @@ const AccordionSection = React.forwardRef(function AccordionSection(
203204

204205
const controlledMode = expanded !== undefined && onToggle;
205206

207+
// eslint-disable-next-line import/no-deprecated
206208
const ids = useUniqueIdWithMock();
207209
const sectionId = id ?? ids.get("accordion-section");
208210
// We need an ID for the header so that the content section's

packages/wonder-blocks-core/src/components/__tests__/id-provider.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23
import {render} from "@testing-library/react";
34

packages/wonder-blocks-core/src/components/__tests__/unique-id-provider.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23
import * as ReactDOMServer from "react-dom/server";
34
import {render} from "@testing-library/react";

packages/wonder-blocks-core/src/components/id-provider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23

34
import UniqueIDProvider from "./unique-id-provider";
@@ -54,6 +55,8 @@ type Props = {
5455
* </IDProvider>
5556
* ```
5657
*
58+
* @deprecated Use `useId` for your ID needs. If you are in a class-based
59+
* component and cannot use hooks, then use the `Id` component.
5760
*/
5861
export default class IDProvider extends React.Component<Props> {
5962
static defaultId = "wb-id";

packages/wonder-blocks-core/src/components/unique-id-provider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-deprecated */
12
import * as React from "react";
23

34
import InitialFallback from "./initial-fallback";
@@ -69,6 +70,9 @@ type Props = {
6970
* )}
7071
* </UniqueIDProvider>
7172
* ```
73+
*
74+
* @deprecated Use `useId` for your ID needs. If you are in a class-based
75+
* component and cannot use hooks, then use the `Id` component.
7276
*/
7377
export default class UniqueIDProvider extends React.Component<Props> {
7478
// @ts-expect-error [FEI-5019] - TS2564 - Property '_idFactory' has no initializer and is not definitely assigned in the constructor.

0 commit comments

Comments
 (0)