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

fix: CSS path in expose-production produce double slashes #664

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

PierreRainero
Copy link
Contributor

@PierreRainero PierreRainero commented Jan 14, 2025

Description

EDIT : Sorry the problem occurs since the 1.3.8 not the 1.3.7.

Since version 1.3.8 our federated CSS files are exposed by a wrong path (under double slashes).
For example, the same configurations of this plugin produce :

  • 1.3.6 :
    http://domain.com/foo/assets/__federation_expose_ModuleName-xxxx.css
    
  • 1.3.8 :
    http://domain.com/foo//assets/__federation_expose_ModuleName-xxxx.css
    

Additional context

The problem come from the usage of join('/') while a "base" vite can end by a slash (which is mostly the case for other plugins configurations).

The current code looks like this :

const baseUrl = '/foo/';
const assetsDir = 'assets';
const cssPath = 'myFile.css';

const href = [baseUrl, assetsDir, cssPath].filter(Boolean).join('/');
// href : "/foo//assets/myFile.css"

With the proposed update :

const baseUrl = '/foo/';
const assetsDir = 'assets';
const cssPath = 'myFile.css';

const href = [baseUrl, assetsDir, cssPath].filter(Boolean).map(part => part.endsWith('/') ? part.substring(0, part.length - 1) : part).join('/');
// href : "/foo/assets/myFile.css"

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Code of Conduct and follow the Commit Convention guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it : I didn't find where to add a related test.

Since version 1.3.7 using a vite.base ending with a slash produce a double slashes on production due to `join('/')` without extra checks (what is not desired).
@PierreRainero PierreRainero marked this pull request as draft January 14, 2025 15:11
@PierreRainero PierreRainero marked this pull request as ready for review January 14, 2025 15:27
@angelsantosa
Copy link

angelsantosa commented Jan 14, 2025

This happens to us.

ALSO this with 1.3.8

MFE: http://remote-domain.com/assets/__federation_expose_ModuleName-xxxx.css

const baseUrl = './';
const assetsDir = 'assets';
const cssPath = 'myFile.css';

const href = [baseUrl, assetsDir, cssPath].filter(Boolean).join('/');

HOST: http://domain.com/some-path Requests: http://remote-domain.com/assets/assets/__federation_expose_ModuleName-xxxx.css

EDIT: Fixed use case

@ruleeeer ruleeeer merged commit 8df65ef into originjs:main Jan 16, 2025
8 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.

3 participants