Skip to content
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

[Proposal] Make able to write React in Typescript #16210

Merged
merged 9 commits into from
Apr 3, 2023

Conversation

takayamaki
Copy link
Contributor

fix #6267

Mastodon has grow to very large class based React written in JavaScript now.

It's very hard for me to understand.
Newcomers will be even more so.

3 years after #6267, it seems that the mainstream of AltJS has become Typescript.

Many of the npm libraries provide own types definitions.
Most of the others are covered by third-party type definitions.

I think better to use Typescript now.

// I understand that Gargron wants prefer to delay large-scale PR merging by some reason.
// I made this PR to prevent duplicate work.

@stale
Copy link

stale bot commented Oct 11, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/wontfix This will not be worked on label Oct 11, 2021
@stale stale bot closed this Oct 22, 2021
@ykzts ykzts reopened this Oct 22, 2021
@stale stale bot removed the status/wontfix This will not be worked on label Oct 22, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@mashirozx
Copy link
Contributor

Hope to know the attitude of the official, so we can decide whether to continue pushing on this migration

@mashirozx
Copy link
Contributor

By the way, I think we can also drop the outdated Redux and so on. In stead of rewrite the v3 front end in TypeScript, it may be a better choice for us to refactory the whole fornt end in new tech stack and move into mastodon v4

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

This pull request has resolved merge conflicts and is ready for review.

@takayamaki
Copy link
Contributor Author

@Gargron rebased now! Can I open this PR?

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2023

This pull request has resolved merge conflicts and is ready for review.

@mashirozx
Copy link
Contributor

great job!

@ykzts
Copy link
Sponsor Member

ykzts commented Mar 5, 2023

Ready for merge?

@takayamaki takayamaki marked this pull request as ready for review March 5, 2023 12:31
@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@mashirozx
Copy link
Contributor

Where is big G 🫣

@github-actions
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@Gargron Gargron merged commit 4520e64 into mastodon:main Apr 3, 2023
@Gargron
Copy link
Member

Gargron commented Apr 3, 2023

I am sorry for taking an outrageously long time to merge this, and I thank you for the persistence.

@ClearlyClaire
Copy link
Contributor

ClearlyClaire commented Apr 3, 2023

Running RAILS_ENV=production bundle exec rails assets:precompile fails after this change.

Interestingly, the build error is different on my machine and in the job to build the Docker image.

On my machine, it chokes on the TypeScript ?? operator, so I guess it is trying to handle the file as Javascript rather than TypeScript:

ERROR in ./app/javascript/hooks/useHovering.ts 1:120
Module parse failed: Unexpected token (1:120)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> import{useCallback,useState}from'react';export const useHovering=animate=>{const[hovering,setHovering]=useState(animate??false);const handleMouseEnter=useCallback(()=>{if(animate)return;setHovering(true);},[animate]);const handleMouseLeave=useCallback(()=>{if(animate)return;setHovering(false);},[animate]);return{hovering,handleMouseEnter,handleMouseLeave};};
 @ ./app/javascript/mastodon/components/avatar.tsx 1:154-203 1:361-372
 @ ./app/javascript/mastodon/features/ui/components/header.jsx
 @ ./app/javascript/mastodon/features/ui/index.jsx
 @ ./app/javascript/mastodon/containers/mastodon.jsx
 @ ./app/javascript/mastodon/main.jsx
 @ ./app/javascript/packs/application.js

For the docker image build job, it fails with:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/preset-typescript' imported from /opt/mastodon/babel-virtual-resolve-base.js
    at new NodeError (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2240:5)
    at packageResolve (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2776:9)
    at moduleResolve (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2804:18)
    at defaultResolve (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2835:13)
    at /opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2855:14
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:45:103)
    at _next (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:46:194)
    at /opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:46:364
    at new Promise (<anonymous>)
    at /opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:46:97
    at resolve (/opt/mastodon/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2847:19)
    at /opt/mastodon/node_modules/@babel/core/lib/config/files/import-meta-resolve.js:20:38
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/opt/mastodon/node_modules/@babel/core/lib/config/files/import-meta-resolve.js:8:103)
    at _next (/opt/mastodon/node_modules/@babel/core/lib/config/files/import-meta-resolve.js:9:194) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Unfortunately, I'm not knowledgeable enough in webpack and babel to figure out what is going on exactly.

EDITED: This has been addressed in #24374

renchap added a commit to renchap/mastodon that referenced this pull request Apr 3, 2023
- Babel plugins need not to be dev deps, as the docker image only install non-dev dependencies and builds the assets
- Somehow Webpack does not support the `??` ES2020 syntax, so we need to transpile it. This is not ideal and can occur on other modern syntax used in TS code, but this fixes the issue for now
- We are using Webpack 4, not 5, the types definition is updated accordingly
Gargron pushed a commit that referenced this pull request Apr 3, 2023
@takayamaki takayamaki deleted the proposal/typescript branch April 4, 2023 19:48
skerit pushed a commit to 11ways/mastodon that referenced this pull request Jul 7, 2023
Co-authored-by: berlysia <berlysia@gmail.com>
Co-authored-by: fusagiko / takayamaki <takayamaki@users.noreply.github.com>
skerit pushed a commit to 11ways/mastodon that referenced this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] change frontend language JavaScript to TypeScript
7 participants