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: uploaded svg icon not showing #3179

Merged
merged 24 commits into from
Jun 24, 2024
Merged

fix: uploaded svg icon not showing #3179

merged 24 commits into from
Jun 24, 2024

Conversation

Arukuen
Copy link
Contributor

@Arukuen Arukuen commented May 6, 2024

fixes #3103

Details of the issue and the solution: https://www.notion.so/SVG-icon-only-shows-up-on-some-blocks-with-icon-3103-94b9c7925d1f4eaba8ebb2752f4b1660?pvs=4

TLDR: The SVG that can be uploaded by the users might have inline style which takes precedence specially since this can be applied to the lowest level which is the <path> element. This PR fixes the issue by applying the fill directly to <path> to have higher precedence.

@Arukuen
Copy link
Contributor Author

Arukuen commented May 6, 2024

Will ask API Key to test solution for Map

Copy link

github-actions bot commented May 6, 2024

🤖 Pull request artifacts

file commit
pr3179-stackable-3179-merge.zip 43dcf94

github-actions bot added a commit that referenced this pull request May 6, 2024
github-actions bot added a commit that referenced this pull request May 7, 2024
@Arukuen Arukuen marked this pull request as ready for review May 7, 2024 03:21
@Arukuen Arukuen marked this pull request as draft May 7, 2024 13:59
github-actions bot added a commit that referenced this pull request May 8, 2024
@Arukuen Arukuen marked this pull request as ready for review May 8, 2024 04:12
github-actions bot added a commit that referenced this pull request May 8, 2024
src/block/icon-list-item/style.scss Outdated Show resolved Hide resolved
src/components/icon-search-popover/index.js Outdated Show resolved Hide resolved
src/block/icon-list-item/style.scss Outdated Show resolved Hide resolved
src/block/carousel/style.js Outdated Show resolved Hide resolved
src/block/icon-list-item/style.scss Show resolved Hide resolved
src/block/map/util.js Outdated Show resolved Hide resolved
src/block/map/util.js Outdated Show resolved Hide resolved
github-actions bot added a commit that referenced this pull request May 12, 2024
github-actions bot added a commit that referenced this pull request May 12, 2024
github-actions bot added a commit that referenced this pull request May 12, 2024
…elected); only apply SVG shapes fill if color exist
github-actions bot added a commit that referenced this pull request May 12, 2024
@Arukuen Arukuen requested a review from bfintal May 12, 2024 03:56
@andeng1106
Copy link

andeng1106 commented May 16, 2024

@Arukuen Issue has been fixed on the three blocks affected. However, there's one remaining issue for Map block only:

  • Block errors are encountered on Map block when using the pr build. See error in console.
    • Block error happens for existing Map blocks with icons selected from icon library / uploaded an svg icon
    • Steps to replicate:
      1. On 3.12.17, add a Map block
      2. Add a Map Marker
      3. Upload an svg icon or select from icon selection
      4. Save page
      5. Upgrade to pr build
      6. Refresh editor
      7. See block error
    Screenshot 2024-05-16 at 9 46 27 AM

@Arukuen
Copy link
Contributor Author

Arukuen commented May 20, 2024

@andeng1106 Since the SVG is serialized for map block, the iconURL of the generated icon will also change when the application of attribute (which this PR did to apply the fill to SVG shapes) is changed. That is why the value of the url property for the data-icon-option for the production build and the PR build are different which causes the issue.

To address this, we can advise affected users to use the "Attempt Block Recovery" feature, which successfully reformats the URL to match the current build and resolves the block error. However, I would like ask for suggestion if there is a better approach.

@bfintal
Copy link
Contributor

bfintal commented May 20, 2024

@Arukuen since we are encountering a block error that can be recovered, we'll need to add some deprecation code to handle migration of the icon. The expected behavior is for the map block not to encounter an error upon upgrading to this new build

github-actions bot added a commit that referenced this pull request May 27, 2024
github-actions bot added a commit that referenced this pull request May 27, 2024
@bfintal bfintal changed the base branch from develop to fix/2338 May 29, 2024 12:40
@bfintal bfintal changed the base branch from fix/2338 to develop May 29, 2024 12:41
Copy link
Contributor

@bfintal bfintal left a comment

Choose a reason for hiding this comment

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

It's great that deprecation is already handled, but it's also a good idea to further separate our deprecated code so it doesn't mingle with our up-to-date functionality. Currently, our deprecated code is located inside the util.js code:

export const getIconOptions = ( attributes, isDeprecated ) => {
    // ...
    if ( isDeprecated ) {
        // ...

I recommend reverting back to the original, then create a function specific for the needs of the deprecation inside src/block/map/deprecated.js that uses the original getIconOptions instead. This way, all our deprecated code stays out of our main code.

// file: src/block/map/deprecated.js
import { getIconOptions } from './utils'

const getIconOptions_3_13_0 = attributes => {
    const newAttributes = { ...attributes }
    // Do things required for the deprecation...
    return getIconOptions( newAttributes )
}

addFilter( 'stackable.map.util.applySVGAttributes', 'stackable/3.13.0', ( output, attributes, props ) => {
	if ( semverCompare( props.version, '<', '3.13.0' ) ) {
		return getIconOptions_3_13_0( attributes )
	}
	return output
} )

data-icon-options={ JSON.stringify( getIconOptions( attributes ) ) }
data-icon-options={ JSON.stringify(
applyFilters(
'stackable.map.util.applySVGAttributes',
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend changing the name of this filter because if you look at where this filter is being used, it's not related to util.applySVGAttributes. I feel like stackable.map.icon-options makes more sense here:

Suggested change
'stackable.map.util.applySVGAttributes',
'stackable.map.icon-options',

Also change the corresponding code that uses this filter

github-actions bot added a commit that referenced this pull request Jun 7, 2024
@bfintal bfintal merged commit 89baa41 into develop Jun 24, 2024
1 of 6 checks passed
@bfintal bfintal deleted the fix/upload-svg-icon branch June 24, 2024 07:46
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.

SVG icon only shows up on some blocks with icon
3 participants