Decouple twenty-ui Avatar from app server-URL config (#21968)

Makes `twenty-ui`'s `Avatar` render the `avatarUrl` it receives instead
of building it from `window._env_`/`window.location` at module load, so
the library no longer depends on the app environment. URL resolution
moves to `twenty-front` via a `getAbsoluteImageUrl` helper applied at
the call sites.

Part of making twenty-ui a standalone library.
This commit is contained in:
Raphaël Bosi
2026-06-22 18:38:00 +02:00
committed by GitHub
parent e59e102448
commit 5f22908588
47 changed files with 198 additions and 115 deletions
@@ -14,6 +14,44 @@ describe('getImageAbsoluteURI', () => {
expect(result).toBe(imageUrl);
});
it('should return http absolute url unchanged', () => {
const imageUrl = 'http://XXX/pic.png';
const baseUrl = 'http://localhost:3000';
const result = getImageAbsoluteURI({ imageUrl, baseUrl });
expect(result).toBe(imageUrl);
});
it('should treat schemes case-insensitively and return them unchanged', () => {
const baseUrl = 'http://localhost:3000';
expect(getImageAbsoluteURI({ imageUrl: 'HTTPS://XXX', baseUrl })).toBe(
'HTTPS://XXX',
);
expect(
getImageAbsoluteURI({ imageUrl: 'Data:image/png;base64,AAAA', baseUrl }),
).toBe('Data:image/png;base64,AAAA');
});
it('should return data URIs unchanged', () => {
const imageUrl = 'data:image/png;base64,iVBORw0KGgo=';
const baseUrl = 'http://localhost:3000';
const result = getImageAbsoluteURI({ imageUrl, baseUrl });
expect(result).toBe(imageUrl);
});
it('should return blob URLs unchanged', () => {
const imageUrl = 'blob:http://localhost:3000/123e4567-e89b-12d3';
const baseUrl = 'http://localhost:3000';
const result = getImageAbsoluteURI({ imageUrl, baseUrl });
expect(result).toBe(imageUrl);
});
it('should return protocol-relative URLs unchanged', () => {
const imageUrl = '//cdn.example.com/pic.png';
const baseUrl = 'http://localhost:3000';
const result = getImageAbsoluteURI({ imageUrl, baseUrl });
expect(result).toBe(imageUrl);
});
it('should return fully formed url if imageUrl is a relative url starting with /', () => {
const imageUrl = '/path/pic.png';
const baseUrl = 'http://localhost:3000';
@@ -7,7 +7,13 @@ export const getImageAbsoluteURI = ({
imageUrl,
baseUrl,
}: getImageAbsoluteURIProps): string => {
if (imageUrl.startsWith('https:') || imageUrl.startsWith('http:')) {
const lowerCaseImageUrl = imageUrl.toLowerCase();
const isAlreadyAbsoluteUri =
['http:', 'https:', 'data:', 'blob:'].some((scheme) =>
lowerCaseImageUrl.startsWith(scheme),
) || imageUrl.startsWith('//');
if (isAlreadyAbsoluteUri) {
return imageUrl;
}