-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Migrate react-scripts to vite #696
base: master
Are you sure you want to change the base?
Conversation
Ok, to sum it up. I tried to update the router, but that is even worse. They broke the complete API and do not even provide a migration script for it. As I mainly develop in Angular I need to read about react before I continue, but it seems that this upgrade to vite is depending on updating all libs to a more current version. If someone else here have a strategy how to update the ui, any feedback is welcome. |
@mfechner I feel you (:, I think the only good way it to start from scratch and copy component by component into a new project, so that you don't have to fix 100 errors to get something working. It's on my todo list, sadly it's multi hour effort. |
@jmattheis thanks a lot for your feedback. I currently study react to better understand react itself. I'm on this task but it will take some time ;) |
The codebase is quite old, pre react hooks. In my experience it wasn't that ergonomic to use contexts for global state, so I've used a lib. Currently I like https://github.com/pmndrs/zustand for it's simplicity and small footprint. |
I started now with a rewrite, but this will be a massiv change.
I think it will be nearly impossible to get this changes sliced into small commit, as all steps link somehow together. I update you, if I have something to show, but it will for sure take some days maybe some weeks. |
f296d85
to
1bf4902
Compare
In DEV mode, you just do: go run . (cd ui && yarn start) In dev mode there is a proxy in vite used to not have CORS problem. You can access the UI on: http://localhost:5173 The UI prefix every request to the backup with `/api` so the proxy can correctly handle it, the proxy strips the `/api` so the backend is equal to production mode.
changing (observed) observable values without using an action
1bf4902
to
3d6fca9
Compare
This is now a first version we can start. There are some todos left (infinite loading component for messages), but it is now a good starting point. The only problem I have is that puppeteer sometimes is just not loading the page and therefore tests are not running. @jmattheis would be nice if you can have a look, it was really a lot of work |
All tests are now working fine for me. |
I'll have a look at this in the coming days, but I'll take some time. |
thank you very much. I found other small issues I corrected in the meantime. The problems I found is that for most actions a submit or a click on a button was not blocking (running in background), which I reverted to the behaviour the released gotify version has. Later we can addnice indicators, if you e.g. click on Submit the button is replaced by an loading indicator. I have here some very nice ideas, but I will provide this later in another PR, as that is not related to this topic. Let us first get the update to react 19 merged, then we can continue further in smaller steps. Maybe we can release these changes as a beta version to enable users testing it. |
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.
Not finished with reviewing, this was only glancing through some files.
ui/serve.go
Outdated
@@ -32,7 +31,7 @@ func Register(r *gin.Engine, version model.VersionInfo, register bool) { | |||
return strings.Replace(content, "%CONFIG%", string(uiConfigBytes), 1) | |||
} | |||
|
|||
ui := r.Group("/", gzip.Gzip(gzip.DefaultCompression)) |
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 cannot reproduce the net:ERR_INCOMPLETE_CHUNKED_ENCODING
error with your listed steps:
cd ui
yarn build
yarn run test user
with having the compression enabled here.
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.
<LoadingSpinner /> | ||
) : hasMessages ? ( | ||
<div style={{width: '100%'}} id="messages"> | ||
{/* TODO: maybe replace ReactInfitite with react-window, which is also documented here: https://mui.com/material-ui/react-list/#virtualized-list */} |
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've recently tried a lot of window libraries for another project and landed on https://tanstack.com/virtual/latest/docs/introduction react-window doesn't play to well with having a window over the whole screen.
} | ||
|
||
const initialUiState: UiState = { | ||
themeKey: 'dark', |
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'm not sure I like this too, previously this was local component state, because it was only used in two places, and passed downwards to one component. Sure adding this to the global state can be done, but local component state is better as it's simpler and easier to navigate.
These refactorings making this review much more effort as it's not just library change / upgrades, but also logic changes which aren't 100% necessary.
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 had a lot of problems in the beginning to understand which prop is passed to which component and why
Using a global state reduces the need of props drilling which is making the componets match leaner and easier to read.
But if you prefer a global state in e.g. app.tsx, I can remove these UI related states from the global state and move it to app.tsx and pass them via props drilling to the components.
But to be honest it will be technically equal and will just make the components harder to read.
But as you prefer.
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 prefer it to be as close as possible to the original implementation for now, as it makes less changes to review and less possibility of bugs, because the code already runs for some time. This includes the moving of the selected plugin state into redux.
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.
ok, I will move the state/slice/action definition to the component.
But I will not remove the ui state management and will change everything back to prop drilling.
This is error prone and we will for sure just add new bugs by this. The UI state is working perfectly fine.
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 error prone and we will for sure just add new bugs by this.
How is it error prone to pass properties to sub components? TypeScript is used, so it's not like you can miss passing the props?
Rewrite all components to functional component using hooks Upgrade react-router to 7.1.0 Use reduxjs/toolkit and react-redux for state management Upgrade material to 6.3.0 Updated most dependencies to current versions
This caused a failure correctly forwarding the user to the login page
6cd4b90
to
cf08815
Compare
…o missing network
Replace react-codemirror2 which is unmaintained by @uiw/react-codemirror and applied required API changes to ReactMarkdown
… the store more than once
…container and can be accessed for the windows host. This is required to use/test plugins with gotify
while working with the production bundled application.
…ld not happen, as the key on already rendered table does not change)
We hold now all messages in the state. If message of one app are refresh, make sure to sort them by date into the existing messages
Axios does not need this for error handling
…f the matching component
Except for the delete actions, as the test does not expect it there
cf08815
to
92a9608
Compare
Failing tests seem to be related to puppeteer upgrade. I will work through the commits again and will maybe rebase some of them, so they match better. @jmattheis the current implementation does not have the virtual scrolling for messages, should I include it here, ot as another PR? |
Fixes #695
To test this modification:
Now access the address
yarn start
shows you.