Skip to content

Conversation

@hophiphip
Copy link

@hophiphip hophiphip commented Aug 3, 2025

Hi, this PR contains some refactoring that makes package compatible with React 18/19.

Changes:

  • Updated library and demo app dependencies versions;
  • Removed react-scripts (outdated) in demo app in favor of vite/vitest;
  • Minor changes in demo app code to make it work with the new React and vite;
  • Added proper TypeScript definitions for MathQuill;
  • Updated library rollup config to properly bundle type definitions;
  • Refactored EquationEditor component from ClassComponent to FunctionComponent;
  • Updated EquationEditor component props to support more customization (left previous props for backward compatibility).

UPDATE(1)

  • Replaced require("mathquill/build/mathquill") with import in abb8f26 as it might break user production build.

@V0XNIHILI V0XNIHILI requested a review from Copilot August 12, 2025 10:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes the equation editor package to support React 18/19 by refactoring core components and updating the build system. The changes replace the legacy class-based EquationEditor with a functional component implementation while maintaining backward compatibility.

  • Refactored EquationEditor from ClassComponent to FunctionComponent with hooks
  • Added comprehensive TypeScript definitions for MathQuill library
  • Updated build system from react-scripts to Vite and upgraded Rollup configuration

Reviewed Changes

Copilot reviewed 19 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/types.ts Added comprehensive TypeScript definitions for MathQuill v1 and v3 APIs
src/mathquill.ts Created module for importing MathQuill build with TypeScript ignore
src/jquery.ts Extracted jQuery setup into separate module
src/index.tsx Refactored EquationEditor from class to functional component with hooks
rollup.config.js Updated build configuration with modern plugins and TypeScript support
package.json Upgraded dependencies to support React 18/19 and modern tooling
demo/* Migrated demo app from react-scripts to Vite with updated dependencies

src/mathquill.ts Outdated
@@ -0,0 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The @typescript-eslint/ban-ts-ignore rule is deprecated. Use @typescript-eslint/ban-ts-comment instead.

Suggested change
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in: 3d07bd7

src/jquery.ts Outdated
// Import JQuery, required for the functioning of the equation editor
import jQuery from "jquery";

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The @typescript-eslint/ban-ts-ignore rule is deprecated. Use @typescript-eslint/ban-ts-comment instead.

Suggested change
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in: e0309a3

src/index.tsx Outdated
}
}

function useCallbackRef<T extends (...args: any[]) => any>(callback: T | undefined): T {
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Using 'any' type reduces type safety. Consider using a more specific type or 'unknown' if the type is truly dynamic.

Suggested change
function useCallbackRef<T extends (...args: any[]) => any>(callback: T | undefined): T {
function useCallbackRef<T extends (...args: unknown[]) => unknown>(callback: T | undefined): T {

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in: aa1f0c2

@hophiphip
Copy link
Author

@V0XNIHILI, I have also removed the default style that hides MathQuill border (default styles: https://github.com/flw0/equation-editor-react/blob/master/src/index.tsx#L95) so that user can have more control over styling.

Is this ok or it would be better to keep the default styles?

@V0XNIHILI
Copy link
Collaborator

V0XNIHILI commented Aug 12, 2025

Hey @hophiphip, thanks a ton for the extensive PR, it looks great! It's been a while since I used TS/React, hence the co-pilot review. Can you confirm that the project runs just as before (ie the Github pages deployment demo should still work)?

Then I will merge with main and push to npm!

@hophiphip
Copy link
Author

I have tested demo application in DEV and PROD build, and it was working without any issues.
And I have also been using a forked version of this library in my own project and did not encounter any issues.

However, I am not 100% sure about GitHub pages. I did not apply any significant changes to the project configuration and kept application and library scripts in package.json same as before, so it should work just as before. But, current GitHub workflow seems to use an older node version..which might prevent yarn from working properly..

  1. Well.. just in case I can try to test if GitHub workflow runs locally (with act);
  2. Also, as I mentioned in this comment: Refactoring package to work with the latest React version #88 (comment). I have removed the default style, so for now EquationEditor has this border (should we keep it?):
2025-08-12-19:12:46-screenshot

@hophiphip
Copy link
Author

hophiphip commented Aug 12, 2025

ok..i have tested whether node 12.x will work with current setup..and it failed

2025-08-12-19:20:44-screenshot

I will look into a possible way of fixing this issue without changing workflow config

@hophiphip
Copy link
Author

Ok, I failed to find an adequate way of supporting an older NodeJS version.

The issue is in this line:

NodeJS 12.x is EOL:
2025-08-12-19:29:20-screenshot

and project dependencies do not support older NodeJS version.

As much as it pains me to say, but for GitHub pages to work properly it is necessary to increment Node JS version:

-node-version: [12.x]
+node-version: [22.x]

@hophiphip
Copy link
Author

hophiphip commented Aug 12, 2025

Changes to the config for GitHub workflow to work properly:
https://github.com/hophiphip/equation-editor-react/pull/1/files

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.

2 participants