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

Replace react-script with vite #471

Merged
merged 11 commits into from
May 31, 2024
Merged

Replace react-script with vite #471

merged 11 commits into from
May 31, 2024

Conversation

geichelberger
Copy link
Contributor

@geichelberger geichelberger commented May 27, 2024

Vite was chosen because of opencast/opencast-editor#1265

Vite was chosen because:

Straightforward migration
Relatively similar set of opinions as CRA
Optimized for single page applications like ours
Popular

I didn't reimplement the dev mode with the mocks.

@geichelberger geichelberger marked this pull request as ready for review May 27, 2024 22:20
@Arnei
Copy link
Member

Arnei commented May 28, 2024

This somewhat silently removes the option to start the admin ui with mock data. While I'm not necessarily against this, I think it could be "possibly controversial"? Furthermore, is this breaking the stuff Lars is working on, like #416?

@geichelberger
Copy link
Contributor Author

Was the code necessary to deploy it like that?

@Arnei
Copy link
Member

Arnei commented May 28, 2024

I actually have no idea, I've just been reading the comments on Github and it seemed like it might clash with this PR.

Copy link
Member

@Arnei Arnei left a comment

Choose a reason for hiding this comment

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

Good riddance CRA, hello Vite!

Works and looks good to me, the comments below are just nitpicks, I am more than willing to approve this. Although we should still discuss if we want to get rid of the mock data. (Personally I never use it so I wouldn't mind if it was gone).

package.json Outdated
"@types/dompurify": "^3.0.5",
"@types/http-proxy": "^1.17.14",
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be going unused.

package.json Outdated
Comment on lines 80 to 82
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
Copy link
Member

Choose a reason for hiding this comment

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

Explicitly importing these seems to be unnecessary?

package.json Outdated
@@ -74,10 +72,21 @@
"@babel/plugin-syntax-optional-chaining": "^7.8.3",
"@babel/preset-env": "^7.23.8",
"@babel/preset-react": "^7.24.1",
Copy link
Member

Choose a reason for hiding this comment

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

Gettring rid of CRA should also mean that we can get rid of babel!

README.md Show resolved Hide resolved
@geichelberger
Copy link
Contributor Author

As the test deployments are only static files, removing the proxy should not cause any trouble.

@lkiesow
Copy link
Member

lkiesow commented May 28, 2024

It's not creaking the test deployment to GitHub pages, but in the current form, it would break the test containers (introduced in #470). At least with the current documentation.

[…] removing the proxy should not cause any trouble.

Does that mean you also cannot proxy API data from Opencast?

Copy link
Member

@lkiesow lkiesow left a comment

Choose a reason for hiding this comment

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

Misunderstood that:

README.md Outdated

This assumes you have an Opencast instance running at `http://localhost:8080`
to which the development server will then proxy all the backend request,
This assumes you have an internet connection to which the development server will then proxy all the backend request,
Copy link
Member

Choose a reason for hiding this comment

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

Can we explicitly state that the default proxy target is https://develop.opencast.org? That “the internet” is proceed is rather vague 😁

@lkiesow
Copy link
Member

lkiesow commented May 29, 2024

Since #470 got merged, can you update the test comment:

Local test with mock data
```
podman run --rm -it -p 127.0.0.1:3000:3000 ${{ steps.meta.outputs.tags }}
```
Proxy data from develop.opencast.org
```
podman run --rm -it -p 127.0.0.1:3000:3000 -e PROXY_TARGET=https://develop.opencast.org ${{ steps.meta.outputs.tags }}
```

This should now probably be something like:

 Run test server using develop.opencast.org as backend:
 ``` 
 podman run --rm -it -p 127.0.0.1:3000:3000 ${{ steps.meta.outputs.tags }} 
 ``` 

 Specify a different backend like stable.opencast.org:
 ``` 
 podman run --rm -it -p 127.0.0.1:3000:3000 -e PROXY_TARGET=https://stable.opencast.org ${{ steps.meta.outputs.tags }} 
 ``` 

Copy link
Contributor

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

- Change path variables
- Fix division warning
- Add static asset handling hint
- Remove ts-expect-error
This replaces the vague formulation `the internet`with the default target
for API calls.
@lkiesow
Copy link
Member

lkiesow commented May 30, 2024

Sorry for finding another issue 🙈

This causes the container to fail since they do not contain a browser:

❯ podman run --rm -it -p 127.0.0.1:3000:3000 opencast-admin-interface:6dfe2dc                                           

> [email protected] start
> vite

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

  VITE v5.2.11  ready in 207 ms

  ➜  Local:   http://localhost:3000/
  ➜  Network: use --host to expose
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'http://localhost:3000/' ]
}

Node.js v20.13.1

The vite server also listens to localhost only which does not work with the containers.

There may be a better way, but this will fix the issues:

diff --git a/Dockerfile b/Dockerfile
index 2782425b1f..1890183c3c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -7,4 +7,5 @@ WORKDIR /admin-interface
 RUN npm ci
 
 ENV CI true
+ENV BROWSER none
 CMD [ "npm", "start" ]
diff --git a/package.json b/package.json
index 4a14ced112..c0bd48faa9 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,7 @@
     "yup": "^1.4.0"
   },
   "scripts": {
-    "start": "vite",
+    "start": "vite --host 0.0.0.0",
     "build": "tsc && vite build",
     "serve": "vite preview",
     "test": "vitest"

- Do not open browser
- Listen on all addresses
@geichelberger
Copy link
Contributor Author

I did not alter the package.json because I would not expect vite to listen on all addresses in a dev environment. Instead, I added the host option to the CMD instruction.

@opencast opencast deleted a comment from github-actions bot May 31, 2024
@lkiesow
Copy link
Member

lkiesow commented May 31, 2024

Great. Tried that but without the --. Didn't know that I need to separate that. Thanks. Merging…

@lkiesow lkiesow merged commit b91dedb into opencast:main May 31, 2024
3 checks passed
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.

4 participants