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

850 feature request migrate to vite #882

Merged
merged 48 commits into from
Apr 15, 2024
Merged

Conversation

DonKoko
Copy link
Contributor

@DonKoko DonKoko commented Mar 26, 2024

Migrating shelf to Vite thanks to @rphlmr
Most files changed are cleanup to make Vite work.
We have completely removed barrel imports as they don't work with Vite.
Moreover relevant changes are:

  • Added vite.config
  • server middleware is slightly adjusted
  • updated dockerfiles
  • fixing css imports to be Vite compliant
  • Server middleware is slightly adjusted to handle new folder/file structure

@DonKoko DonKoko linked an issue Mar 26, 2024 that may be closed by this pull request
@DonKoko DonKoko mentioned this pull request Mar 26, 2024
5 tasks
@DonKoko
Copy link
Contributor Author

DonKoko commented Mar 27, 2024

@rphlmr I found an issue. react-map-gl doesn't work with vite.
In order to test it you need to scan a QR and allow the app to access your location.
Once the location is saved in the DB, the app will attempt to render the map on the asset page. That will break the asset page. This is the error the app throws:

  <-- GET /assets/react_devtools_backend_compact.js.map
[23:34:15.405] ERROR (58893): The asset you are trying to access does not exist or you do not have permission to access it.
    err: {
      "cause": {
        "name": "NotFoundError",
        "code": "P2025",
        "clientVersion": "5.10.2",
        "stack":
            NotFoundError: No Asset found
                at /Users/donkoko/devs/shelf/webapp/node_modules/@prisma/client/runtime/library.js:32:611
                at async /Users/donkoko/devs/shelf/webapp/node_modules/@prisma/client/runtime/library.js:32:551
                at async Module.getAsset (/Users/donkoko/devs/shelf/webapp/app/modules/asset/service.server.ts:44:12)
                at async loader (/Users/donkoko/devs/shelf/webapp/app/routes/_layout+/assets.$assetId.tsx:101:19)
                at async Object.callRouteLoaderRR (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/server-runtime/dist/data.js:52:16)
                at async callLoaderOrAction (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:4166:16)
                at async Promise.all (index 3)
                at async loadRouteData (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:3638:19)
                at async queryImpl (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:3481:20)
                at async Object.query (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:3381:18)
                at async handleDocumentRequestRR (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/server-runtime/dist/server.js:184:15)
                at async requestHandler (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/server-runtime/dist/server.js:108:18)
                at async file:///Users/donkoko/devs/shelf/webapp/node_modules/remix-hono/build/handler.js:7:16
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async file:///Users/donkoko/devs/shelf/webapp/node_modules/remix-hono/build/session.js:19:9
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async logger2 (/Users/donkoko/devs/shelf/webapp/server/logger.ts:46:3)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async eval (/Users/donkoko/devs/shelf/webapp/server/middleware.ts:75:5)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async eval (/Users/donkoko/devs/shelf/webapp/server/middleware.ts:75:5)
                at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
                at async file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/hono-base.js:188:25
                at async getRequestListener.errorHandler.err (file:///Users/donkoko/devs/shelf/webapp/node_modules/@hono/vite-dev-server/dist/dev-server.js:87:32)
                at async responseViaResponseObject (file:///Users/donkoko/devs/shelf/webapp/node_modules/@hono/node-server/dist/index.mjs:300:15)
      },
      "label": "Assets",
      "title": "Asset not found",
      "additionalData": {
        "id": "react_devtools_backend_compact.js.map",
        "organizationId": "clu021ne5000011g39745fvxm"
      },
      "shouldBeCaptured": true,
      "status": 500,
      "traceId": "srxw2shu6mwtr59fqm7fwcof",
      "name": "ShelfError",
      "message": "The asset you are trying to access does not exist or you do not have permission to access it.",
      "stack":
          ShelfError: The asset you are trying to access does not exist or you do not have permission to access it.
              at Module.makeShelfError (/Users/donkoko/devs/shelf/webapp/app/utils/error.ts:46:12)
              at loader (/Users/donkoko/devs/shelf/webapp/app/routes/_layout+/assets.$assetId.tsx:143:43)
              at async Object.callRouteLoaderRR (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/server-runtime/dist/data.js:52:16)
              at async callLoaderOrAction (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:4166:16)
              at async Promise.all (index 3)
              at async loadRouteData (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:3638:19)
              at async queryImpl (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:3481:20)
              at async Object.query (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/router/dist/router.cjs.js:3381:18)
              at async handleDocumentRequestRR (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/server-runtime/dist/server.js:184:15)
              at async requestHandler (/Users/donkoko/devs/shelf/webapp/node_modules/@remix-run/server-runtime/dist/server.js:108:18)
              at async file:///Users/donkoko/devs/shelf/webapp/node_modules/remix-hono/build/handler.js:7:16
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async file:///Users/donkoko/devs/shelf/webapp/node_modules/remix-hono/build/session.js:19:9
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async logger2 (/Users/donkoko/devs/shelf/webapp/server/logger.ts:46:3)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async eval (/Users/donkoko/devs/shelf/webapp/server/middleware.ts:75:5)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async eval (/Users/donkoko/devs/shelf/webapp/server/middleware.ts:75:5)
              at async dispatch (file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/compose.js:29:17)
              at async file:///Users/donkoko/devs/shelf/webapp/node_modules/hono/dist/hono-base.js:188:25
              at async getRequestListener.errorHandler.err (file:///Users/donkoko/devs/shelf/webapp/node_modules/@hono/vite-dev-server/dist/dev-server.js:87:32)
              at async responseViaResponseObject (file:///Users/donkoko/devs/shelf/webapp/node_modules/@hono/node-server/dist/index.mjs:300:15)
    }

However its actually the ShelfMap component that breaks. I saw that you placed a comment in the file, linking to a github discussion (visgl/react-map-gl#2272) however the fix you did doesn't seem to work. I also read the discussion and I tried to install 7.2.0-beta.1 but that also didn't work for me but I am not sure why.
The imports would just fail:
Screenshot 2024-03-27 at 08 31 43

You can check this repo: https://github.com/tordans/berlin-bikenetwork-monitoring/blob/main/package.json. They are not using vite, but he is using 7.2.0-beta.1 and it seems to work.

@rphlmr
Copy link
Contributor

rphlmr commented Mar 27, 2024

@DonKoko I pushed a fix. I hope it solves the issue on staging env

@DonKoko
Copy link
Contributor Author

DonKoko commented Apr 1, 2024

Something I noticed when I was testing an un-related task.
So if you scan a qr code, it usually redirects you to the asset page with some url params. When redirected after a scanning of a QR code we automatically show the actions dropdown.
For some reason this is not working in the vite branch. I tried it in a few different branches and there was no issue.
Screenshot 2024-04-01 at 12 55 25
You can see in the screenshot the overlay shows but not the menu.

It should look like this
Screenshot 2024-04-01 at 12 57 52

So after some testing and switching between branches, i realized that if I dont run npm i after switching away from vite branch, it doesn't work again, so I assume its because of this: https://github.com/Shelf-nu/shelf.nu/pull/882/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R49

Was there something related to vite that required this update?

P.S. I have temporarily removed vite from staging app so we can test some other features.

@rphlmr
Copy link
Contributor

rphlmr commented Apr 1, 2024

Thanks for sharing.
I'll look at that asap.
The reason why I have updated radix dependencies is because they improve esm support. Some dependencies were causing issues.
https://www.radix-ui.com/primitives/docs/overview/releases
Except select, they all are minors.
I'll come back with a fix.

@DonKoko
Copy link
Contributor Author

DonKoko commented Apr 1, 2024

@rphlmr yeah i tried setting Dropdown dependency back to the prev version, but indeed the import was then broken. So we have to figure out a bit more about this. Glad we left vite in testapp for some more time. This is such a specific case, finding it was honestly kinda tricky and just got lucky.

@rphlmr
Copy link
Contributor

rphlmr commented Apr 2, 2024

@DonKoko action dropdown should be ok
cf 5deeb24

@DonKoko DonKoko merged commit 6b2fd83 into main Apr 15, 2024
4 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.

[Feature request]: Migrate to Vite
2 participants