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

BUGFIX: Always bundle custom svgs instead of using resource:// paths #3836

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const options = {
legalComments: "linked",
loader: {
'.js': 'tsx',
'.svg': 'dataurl',
'.dataurl.svg': 'dataurl',
'.svg': 'text',
'.vanilla-css': 'css',
'.woff2': 'file'
},
Expand All @@ -53,13 +54,6 @@ const options = {
}
})

// load ckeditor icons as plain text and not via `.svg: dataurl`
// (currently neccessary for the table select handle icon)
onLoad({filter: /node_modules\/@ckeditor\/.*\.svg$/}, async ({path}) => ({
contents: (await require('fs/promises').readFile(path)).toString(),
loader: 'text'
}))

// prefix Fontawesome with "neos-" to prevent clashes with customer Fontawesome
onLoad({filter: /@fortawesome\/fontawesome-svg-core\/styles\.css$/}, async ({path}) => {
const contents = (await require('fs/promises').readFile(path)).toString();
Expand Down
12 changes: 8 additions & 4 deletions packages/neos-ui-containers/src/InsertModeSelector/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';

import {ButtonGroup, Button, Icon} from '@neos-project/react-ui-components';
import {ButtonGroup, Button, ResourceIcon} from '@neos-project/react-ui-components';
import {neos} from '@neos-project/neos-ui-decorators';
import I18n from '@neos-project/neos-ui-i18n';

import style from './style.module.css';

import createAboveIcon from './resources/create-above.svg';
import createBelowIcon from './resources/create-below.svg';
import createInsideIcon from './resources/create-inside.svg';

const MODE_AFTER = 'after';
const MODE_BEFORE = 'before';
const MODE_INTO = 'into';
Expand Down Expand Up @@ -98,7 +102,7 @@ export default class InsertModeSelector extends PureComponent {
size="small"
title={`${i18nRegistry.translate('Neos.Neos:Main:insert')} ${i18nRegistry.translate('above')}`}
>
<Icon icon="resource://Neos.Neos.Ui/Icons/create-above.svg" className={style.iconAlignment} size="1x"/>
<ResourceIcon source={createAboveIcon} className={style.iconAlignment}/>
<I18n id="Neos.Neos.Ui:Main:above" fallback="Above"/>
</Button>
<Button
Expand All @@ -109,7 +113,7 @@ export default class InsertModeSelector extends PureComponent {
size="small"
title={`${i18nRegistry.translate('Neos.Neos:Main:insert')} ${i18nRegistry.translate('below')}`}
>
<Icon icon="resource://Neos.Neos.Ui/Icons/create-below.svg" className={style.iconAlignment} size="1x"/>
<ResourceIcon source={createBelowIcon} className={style.iconAlignment}/>
<I18n id="Neos.Neos.Ui:Main:below" fallback="Below"/>
</Button>
<Button
Expand All @@ -120,7 +124,7 @@ export default class InsertModeSelector extends PureComponent {
size="small"
title={`${i18nRegistry.translate('Neos.Neos:Main:insert')} ${i18nRegistry.translate('into')}`}
>
<Icon icon="resource://Neos.Neos.Ui/Icons/create-inside.svg" className={style.iconAlignment} size="1x"/>
<ResourceIcon source={createInsideIcon} className={style.iconAlignment}/>
<I18n id="Neos.Neos.Ui:Main:inside" fallback="Inside"/>
</Button>
</ButtonGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {AssetUpload} from '../../../../Library/index';

import {Thumbnail} from '../../Utils/index';
import {Icon} from '@neos-project/react-ui-components';
import dummyImage from '../../resource/dummy-image.dataurl.svg';
import style from './style.module.css';

export default class PreviewScreen extends PureComponent {
Expand Down Expand Up @@ -52,7 +53,7 @@ export default class PreviewScreen extends PureComponent {
</div>
<img
className={(thumbnail ? style.cropArea__image : style['cropArea__image--placeholder'])}
src={thumbnail ? thumbnail.uri : '/_Resources/Static/Packages/Neos.Neos/Images/dummy-image.svg'}
src={thumbnail ? thumbnail.uri : dummyImage}
style={thumbnail ? thumbnail.styles.thumbnail : {}}
alt={propertyName}
/>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {$get} from 'plow-js';

import AspectRatioDropDown from './AspectRatioDropDown/index';
import CropConfiguration, {CustomAspectRatioOption, LockedAspectRatioStrategy} from './model.js';
import dummyImage from '../../Editors/Image/resource/dummy-image.dataurl.svg';
import style from './style.module.css';

import './react_crop.vanilla-css';
Expand Down Expand Up @@ -182,7 +183,7 @@ export default class ImageCropper extends PureComponent {
const aspectRatioLocked = cropConfiguration.aspectRatioStrategy instanceof LockedAspectRatioStrategy;
const allowCustomRatios = cropConfiguration.aspectRatioOptions.some(option => option instanceof CustomAspectRatioOption);
const {sourceImage, i18nRegistry} = this.props;
const src = sourceImage.previewUri || '/_Resources/Static/Packages/Neos.Neos/Images/dummy-image.svg';
const src = sourceImage.previewUri || dummyImage;

const toolbarRef = el => {
this.toolbarNode = el;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui-components/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function main() {
metafile: true,
loader: {
'.js': 'tsx',
'.svg': 'dataurl',
'.svg': 'text',
'.css': 'copy'
},
plugins: [
Expand Down
5 changes: 5 additions & 0 deletions packages/react-ui-components/src/Icon/resourceIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export interface ResourceIconProps extends Omit<IconProps, 'theme'> {
readonly theme?: ResourceIconTheme;
}

/**
* @deprecated please refrain from using resource paths
Sebobo marked this conversation as resolved.
Show resolved Hide resolved
* use the new react-ui-components/ResourceIcon instead.
* See also https://github.com/neos/neos-ui/issues/2092
*/
class ResourceIcon extends PureComponent<ResourceIconProps> {
public static readonly defaultProps = defaultProps;

Expand Down
9 changes: 3 additions & 6 deletions packages/react-ui-components/src/Logo/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React, {PureComponent} from 'react';
import {ResourceIcon} from '../ResourceIcon';

import logo from './logo.svg';
import logoSvg from './resource/logo.svg';
import style from './style.module.css';

export default class Logo extends PureComponent {
render() {
return (
<div>
<img className={style.logo} src={logo} alt="Neos" />
</div>
);
return <ResourceIcon source={logoSvg} className={style.logo}></ResourceIcon>;
}
}
1 change: 0 additions & 1 deletion packages/react-ui-components/src/Logo/logo.svg

This file was deleted.

5 changes: 5 additions & 0 deletions packages/react-ui-components/src/Logo/resource/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions packages/react-ui-components/src/Logo/style.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.logo {
.logo > svg {
height: 24px;
width: auto;
}
26 changes: 26 additions & 0 deletions packages/react-ui-components/src/ResourceIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import mergeClassNames from 'classnames';
import style from './style.module.css';

type ResourceIconProps = {
source?: string;
className?: string;
label?: string;
}

export function ResourceIcon(props: ResourceIconProps) {
const {source, className, label} = props;

if (!source) {
return null;
}

const classNames = mergeClassNames(
className,
{
[style['resource-icon']]: true
}
);

return <span dangerouslySetInnerHTML={{__html: source}} aria-label={label} className={classNames}></span>;
}
20 changes: 20 additions & 0 deletions packages/react-ui-components/src/ResourceIcon/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.resource-icon {
composes: reset from '../reset.module.css';
display: inline-block;
font: normal normal normal FontAwesome;
font-size: 14px/1;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}


.resource-icon {
display: inline-grid;
width: 100%;
justify-content: center;
}

.resource-icon > svg {
fill: none;
}
1 change: 1 addition & 0 deletions packages/react-ui-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {default as DropDown} from './DropDown';
export {default as Frame} from './Frame';
export {default as Headline} from './Headline';
export {default as Icon} from './Icon';
export {ResourceIcon} from './ResourceIcon';
export {default as IconButton} from './IconButton';
export {default as IconButtonDropDown} from './IconButtonDropDown';
export {default as Label} from './Label';
Expand Down
Loading