Skip to content

Conversation

@nishasy
Copy link
Contributor

@nishasy nishasy commented Nov 7, 2025

Summary:

todo

Issue: none

Test plan:

todo

@nishasy nishasy self-assigned this Nov 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

🗄️ Schema Change: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Size Change: -95 B (-0.02%)

Total Size: 498 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 97.1 kB -95 B (-0.1%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.8 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 99.2 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 13.1 kB
packages/perseus-core/dist/es/index.js 22.4 kB
packages/perseus-linter/dist/es/index.js 7.21 kB
packages/perseus-score/dist/es/index.js 9.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 204 kB
packages/perseus/dist/es/strings.js 7.73 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (8d71d4c) and published it to npm. You
can install it using the tag PR3024.

Example:

pnpm add @khanacademy/perseus@PR3024

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR3024

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR3024

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

I think I like this. I'd love to hear other folks' opinions but I think I'd be interested in proceeding with this.

WidgetEditorState
> {
widget: React.RefObject<React.ElementRef<typeof Editor>>;
widget: React.RefObject<EditorType>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could just move the initialization up here (which I feel is pretty common in class components.

Suggested change
widget: React.RefObject<EditorType>;
widget = React.createRef<EditorType>;

showWidget: props.widgetIsOpen ?? true,
widgetInfo: _upgradeWidgetInfo(props),
};
this.widget = React.createRef();
Copy link
Collaborator

Choose a reason for hiding this comment

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

☝️ Then you could remove this line...

Comment on lines 39 to +40
<DependenciesContext.Provider value={testDependenciesV2}>
<ImageEditor {...props} />
<APIOptionsContext.Provider value={apiOptions}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not asking for a change now... but I suspect we might want a sort of test harness that wraps things in deps and api options... let's see how it goes. :)

Comment on lines +562 to +571
<DependenciesContext.Provider value={testDependenciesV2}>
<APIOptionsContext.Provider
value={{
...ApiOptions.defaults,
flags: getFeatureFlags({"image-widget-upgrade": false}),
}}
>
<ImageEditor onChange={onChangeMock} />
</APIOptionsContext.Provider>
</DependenciesContext.Provider>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could allow ImageEditorWithDependencies to accept a Partial<APIOptions> and then blend that parameter with the defaults that are defined at the top of this file. Might be a touch cleaner... or not. 🤷‍♂️

Suggested change
<DependenciesContext.Provider value={testDependenciesV2}>
<APIOptionsContext.Provider
value={{
...ApiOptions.defaults,
flags: getFeatureFlags({"image-widget-upgrade": false}),
}}
>
<ImageEditor onChange={onChangeMock} />
</APIOptionsContext.Provider>
</DependenciesContext.Provider>,
<ImageEditorWithDependencies
apiOptionOverrides={{
flags: getFeatureFlags({"image-widget-upgrade": false}),
}}
onChange={onChangeMock}
/>

Comment on lines -22 to -27
static propTypes = {
...Changeable.propTypes,
togglePrompt: PropTypes.string,
definition: PropTypes.string,
apiOptions: PropTypes.any,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. Thanks for replacing these instances of PropTypes!


// TODO(jangmi, CP-3288): Remove usage of `UNSAFE_componentWillMount`
UNSAFE_componentWillMount() {
this._editors = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eww... can we just initialize this on line 18 and get rid of this UNSAFE_componentWillMount entirely?

<Table {...(tableProps as PropsFor<typeof Table>)} />
</div>
</div>
<APIOptionsContext.Consumer>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't think of this till I got to the next file (packages/perseus-editor/src/editor.tsx), but you could probably make this PR somewhat less disruptive by wrapping these various widget editors using the withAPIOptions() HoC also. Then you wouldn't need to put the context consumer in all these render functions.

🤔

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants