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

Image preview in string prop control #4890

Merged
merged 12 commits into from
Feb 14, 2024

Conversation

gbalint
Copy link
Contributor

@gbalint gbalint commented Feb 13, 2024

Description:
Simple image preview for string property controls: it shows the image when the string property is a url.

image

Copy link
Contributor

github-actions bot commented Feb 13, 2024

Try me

Copy link

relativeci bot commented Feb 13, 2024

Job #10440: Bundle Size — 61.74MiB (~+0.01%).

2392469(current) vs d299c8d master#10417(baseline)

Warning

Bundle contains 57 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
Job #10440
     Baseline
Job #10417
Regression  Initial JS 34.79MiB(~+0.01%) 34.78MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 20.48% 20.46%
No change  Chunks 28 28
No change  Assets 32 32
No change  Modules 4294 4294
No change  Duplicate Modules 493 493
No change  Duplicate Code 31.01% 31.01%
No change  Packages 455 455
No change  Duplicate Packages 57 57
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
Job #10440
     Baseline
Job #10417
Regression  JS 61.73MiB (~+0.01%) 61.73MiB
Improvement  HTML 11.37KiB (-0.32%) 11.41KiB

View job #10440 reportView feature/image-preview-string-con... branch activityView project dashboard

Copy link
Contributor

github-actions bot commented Feb 13, 2024

Performance test results:
(Chart1)
(Chart2)

@@ -259,3 +259,8 @@ export function isCssFile(filename: string): boolean {
export function isJsOrTsFile(filename: string): boolean {
return isJsFile(filename) || isTsFile(filename)
}

export function isImageUrl(url: string): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

there's also isImage function, we might be able to unify them

export function isImage(str: string): boolean {
const lowerCaseStr = str.toLowerCase()
return imgPattern.test(lowerCaseStr) || lowerCaseStr.startsWith('data:image/')

Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch!

url: string
}
const ImagePreview = React.memo((props: ImagePreviewProps) => {
const [imageCanBeLoaded, setImageCanBeLoaded] = React.useState(true)
Copy link
Contributor

@liady liady Feb 13, 2024

Choose a reason for hiding this comment

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

won't that always start with true on every re-render (even if the url hadn't changed) and so it will always first try to the render the <img> even if the url is bad?

Copy link
Contributor

Choose a reason for hiding this comment

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

it would start with true on every re-mount, but not on every re-render

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What Balazs wrote and when the url is bad we don't even mount the ImagePreview (see line 465)
But I can integrate that check into the ImagePreview component itself (by initializing imageCanBeLoaded with isImageUrl(url))

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, of course, re-mount was what I meant 🤦‍♂️ in any case it's not critical at all

@gbalint gbalint marked this pull request as ready for review February 14, 2024 10:43
@gbalint gbalint merged commit 9df6101 into master Feb 14, 2024
14 checks passed
@gbalint gbalint deleted the feature/image-preview-string-control branch February 14, 2024 15:25
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.

4 participants