vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
904 stars 57 forks source link

feat: Do not force full reload when changing routes #2751

Closed Artur- closed 1 week ago

Artur- commented 1 week ago

HMR now works as following:

When a file inside the views folder changes, the vite plugin for the file router picks that up. After writing file-routes.ts and file-routes.json with the new data, it fires a fs-route-update event through the Vite event bus. It is important to write file-routes.ts also when its contents does not change but some meta info in a view has changed (i.e. when the json file changes). This will propagate the new meta data also to the router configuration.

The custom HMR code in createMenuItems.ts reacts to this events and initiates a re-fetch of window.Vaadin.views from the server. Once the new data is available, the signal the menu is based upon is updated and the menu re-rendered.

Vite reacts on file-routes.ts being changed and propagates HMR events to its importers, which typically is index.tsx that configures the react router using the routes and vaadin-react.tsx which stores the routes so that the Flow router integration can access them. index.tsx reacts to the HMR event by re-rendering the full application with the new routes, updating the React router configuration.

Fixes #2749

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 94.41%. Comparing base (9ee4b80) to head (3436511). Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ages/ts/file-router/src/runtime/createMenuItems.ts 66.66% 2 Missing :warning:
...ile-router/src/vite-plugin/generateRuntimeFiles.ts 87.50% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2751 +/- ## ========================================== - Coverage 94.48% 94.41% -0.07% ========================================== Files 81 81 Lines 2648 2651 +3 Branches 666 670 +4 ========================================== + Hits 2502 2503 +1 - Misses 142 144 +2 Partials 4 4 ``` | [Flag](https://app.codecov.io/gh/vaadin/hilla/pull/2751/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vaadin) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/vaadin/hilla/pull/2751/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vaadin) | `94.41% <78.57%> (-0.07%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vaadin#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

vaadin-bot commented 1 week ago

This ticket/PR has been released with Hilla 24.5.0.beta2 and is also targeting the upcoming stable 24.5.0 version.