-
Notifications
You must be signed in to change notification settings - Fork 357
[DRAFT]: Remove unused code and usages of findDOMNode #2769
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
base: main
Are you sure you want to change the base?
Conversation
🗄️ Schema Change: No Changes ✅ |
Size Change: +3 B (0%) Total Size: 496 kB
ℹ️ View Unchanged
|
🛠️ Item Splitting: No Changes ✅ |
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (e9a8587) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2769 If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR2769 If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR2769 |
@@ -462,7 +461,6 @@ class Matrix extends React.Component<Props, State> implements Widget { | |||
<SimpleKeypadInput | |||
{...inputProps} | |||
style={style} | |||
scrollable={true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nonsense property that doesn't exist, so I've removed it! We simply didn't catch it before as SimpleKeypadInput wasn't very specific about props
@@ -247,6 +246,8 @@ class NumberLine extends React.Component<Props, State> implements Widget { | |||
static contextType = PerseusI18nContext; | |||
declare context: React.ContextType<typeof PerseusI18nContext>; | |||
|
|||
tickControlRef: HTMLInputElement | null = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only ever one input in NumberLine, so I figured I'd simplify this accordingly.
} | ||
}; | ||
|
||
// There's only one input path for the tick control, but the renderer | ||
// expects this method to be implemented. | ||
getInputPaths: () => ReadonlyArray<ReadonlyArray<string>> = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these methods are part of our our main renderer logic, I didn't want to mess with them too much.
I think improving this will require a more holistic and modern approach to our focus handling across Perseus (perhaps a context?).
6010d1f
to
10b363c
Compare
// eslint-disable-next-line react/no-string-refs | ||
const curInput = this.refs[getRefForPath(getInputPath(row, col))]; | ||
const inputID = getRefForPath(getInputPath(row, col)); | ||
const curInput = this.answerRefs[inputID]; | ||
// @ts-expect-error - TS2339 - Property 'getStringValue' does not exist on type 'ReactInstance'. | ||
const curValueString = curInput.getStringValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remove these ts-expect errors as the SimpleKeypadInput never supported these methods, although our TextInput does. (getStringValue, getSelectionStart, getSelectionEnd).
This means that none of this keyboard logic was ever working for our mobile users. However, they were also very unlikely to hit this as it requires hitting specific keys on their mobile device's keyboard.
…s onRender (testing)
} else { | ||
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'focus' does not exist on type 'Element | Text'. | ||
ReactDOM.findDOMNode(inputComponent).focus(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the section of code that was able to be cleaned up by converting SimpleKeypadInput into the forward ref functional component
ref="tick-ctrl" | ||
ref={(ref) => { | ||
this.tickControlRef = ref; | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooo I can simplify this
In my testing and investigations, I simply cannot find any case where this fallback is called.
if (interWidgetPath.length === 0) { | ||
// @ts-expect-error - TS2345 - Argument of type 'Widget | null | undefined' is not assignable to parameter of type 'ReactInstance | null | undefined'. | ||
return ReactDOM.findDOMNode(widget); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only ever seem to hit line 1536 when we are in a Graded Group, but the length is never zero. I've been unable to find any cases where we ever actually need this fallback. I tested every widget in storybook in both desktop/mobile views. The only place we ever satisfy this condition is when we're explicitly forcing the situation in tests.
Summary:
This [DRAFT] PR is currently a proof of concept. I'm testing the results upstream, but please feel free to leave any comments or concerns about my approach.
The main goals of this PR are to:
findDOMNode
as possiblefindDOMNode
Changes Made
Issue: LEMS-XXXX
Test plan: