Skip to content

fix: join servlet context path to Vite base path in dev mode - #12771

Merged
vursen merged 9 commits into
masterfrom
fix/vite-context-path
Jan 25, 2022
Merged

vursen merged 9 commits into
masterfrom
fix/vite-context-path

Conversation

@vursen

@vursen vursen commented Jan 20, 2022 •

Copy link
Copy Markdown
Contributor

Description

When the user runs a Flow application with a servlet context path specified, Vite server's base path, as well as subsequent requests to the Vite server, should start with that context path. The PR takes this approach to address the problem of the app frontend resources not loading correctly when using Vite in combination with a servlet context path. Note, the problem is only specific to the dev mode.

Fixes #12388

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@github-actions

github-actions Bot commented Jan 20, 2022 •

Copy link
Copy Markdown
Contributor

Unit Test Results

   772 files  +  2     772 suites  +2   26m 26s ⏱️ + 2m 23s
5 746 tests +  1  5 695 ✔️ ±0  51 💤 +1  0 ❌ ±0 
5 778 runs  +12  5 726 ✔️ +8  52 💤 +4  0 ❌ ±0 

Results for commit 7551549. ± Comparison against base commit 3131a72.

♻️ This comment has been updated with latest results.

@platosha platosha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good so far!

@vursen
vursen force-pushed the fix/vite-context-path branch 5 times, most recently from 33e9889 to 2de1d1f Compare January 21, 2022 12:57
@vursen vursen changed the title fix: pass servlet context path to Vite fix: pass servlet context path to Vite in dev mode Jan 21, 2022
},
{
name: 'inject-entrypoint-script',
name: 'force-remove-spa-middleware',

@vursen vursen Jan 21, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note: Following the separation of concerns principle, I decided to extract this workaround into a separate plugin.

return [
{
tag: 'script',
attrs: { type: 'module', src: `${basePath}generated/vite-devmode.ts` },

@vursen vursen Jan 21, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note: I decided in favor of the script path being based on the server base path rather than a hard-coded /VAADIN/. It might theoretically be useful in the case the user wants to configure the base property in a custom way.

@vursen vursen self-assigned this Jan 21, 2022
return {
root: 'frontend',
base: basePath,
base: '',

@vursen vursen Jan 21, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note: The --base argument, which the dev server passes to .bin/vite in dev mode from now on, will take precedence over the config's base property.

@vursen
vursen marked this pull request as ready for review January 21, 2022 15:43
@vursen
vursen requested review from Artur- and platosha January 21, 2022 15:53
@vursen
vursen force-pushed the fix/vite-context-path branch 4 times, most recently from 54496f4 to 97d7618 Compare January 24, 2022 09:02
@vursen
vursen force-pushed the fix/vite-context-path branch from 2b50ca1 to 7551549 Compare January 24, 2022 10:36
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vursen vursen changed the title fix: pass servlet context path to Vite in dev mode fix: join servlet context path to Vite base path in dev mode Jan 24, 2022
@vursen
vursen merged commit 063e697 into master Jan 25, 2022
@vursen
vursen deleted the fix/vite-context-path branch January 25, 2022 08:59
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 23.0.0.alpha4 and is also targeting the upcoming stable 23.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vite]: absolute /VAADIN path in scripts with non-root context

3 participants