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

Fixed replaced image in product page #24983

Closed
wants to merge 4 commits into from
Closed

Conversation

NoZTurn
Copy link
Contributor

@NoZTurn NoZTurn commented Jun 16, 2021

with this small code trick ,we can change the replaced image to the newest one immediately the time after the image ajax replaced without the page refresh or reload.

Questions Answers
Branch? 1.7.8.x
Description? with this small code trick ,we can change the replaced image to the newest one immediately the time after the image ajax replaced without the page refresh or reload.
Type? improvement
Category? BO
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #20035.
How to test? Just clear your caches and refresh your product v2 page.
Possible impacts? small change, no other impact.

This change is Reviewable

with this small code trick ,we can change the replaced image to the newest one immediately the time after the image ajax replaced with the page refresh or reload.
@NoZTurn NoZTurn requested a review from a team as a code owner June 16, 2021 09:02
@prestonBot
Copy link
Collaborator

Hello @NoZTurn!

This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community!

@prestonBot prestonBot added 1.7.8.x Branch Improvement Type: Improvement labels Jun 16, 2021
@@ -494,7 +494,7 @@
const imageElement = document.querySelector(
DropzoneMap.savedImage(newImage.image_id),
);
imageElement.src = newImage.image_url;
imageElement.src = newImage.image_url + '?' + Math.random();

Choose a reason for hiding this comment

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

What's the behavior behind this? It's because of browser's cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I think is the browser cache, you can force the browser to renew the new image url after the image uploaded.

Choose a reason for hiding this comment

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

@PierreRambaud wdyt? I really appreciate this little trick

Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to do something properly we have to get the image checksum instead of a random number.
Using Math.random can return twice the same number.

Copy link
Contributor Author

@NoZTurn NoZTurn Jun 16, 2021

Choose a reason for hiding this comment

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

checksum is the best solution, if Math.random() may return a repeat number, we can also use new Date() and its getTime() function instead of Math.random(), because all times a different, so this can avoid the same number repeat.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the image is only load once, why not, otherwise, if it has to be always displayed, we should use the checksum method

Choose a reason for hiding this comment

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

If the image is only load once, why not, otherwise, if it has to be always displayed, we should use the checksum method

Looks like it doesn't have to be always displayed, it's only on replace, in order to kick the browser's cache out which is faster, but maybe every API endpoints can just provide the URL with image checksum : ping @jolelievre

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the image is only load once, why not, otherwise, if it has to be always displayed, we should use the checksum method

Looks like it doesn't have to be always displayed, it's only on replace, in order to kick the browser's cache out which is faster, but maybe every API endpoints can just provide the URL with image checksum : ping @jolelievre

agree with you, I come across that at product list page, the image is also not updated after image replacement because of the browser's cache, so maybe we have to makes some change at the image core API.

@NoZTurn NoZTurn mentioned this pull request Jun 16, 2021
@NeOMakinG
Copy link

@PrestaShop/prestashop-core-developers As this PR is not a bug but an improvement, do we want it to target the 1.7.8.x branch? It's fast to merge and improve the new product page, but the new build is really close :/

checksum is the best solution,but us a different tail number is more simple, if Math.random() may return a repeat number, we can also use new Date() and its getTime() function instead of Math.random(), because all times a different, so this can avoid the same number repeat.

I renew my pull request above.
…e/Dropzone.vue

Co-authored-by: GoT <PierreRambaud@users.noreply.github.com>
PierreRambaud
PierreRambaud previously approved these changes Jun 17, 2021
Progi1984
Progi1984 previously approved these changes Jun 18, 2021
@Progi1984 Progi1984 changed the title Update Dropzone.vue Fixed replaced image in product page Jun 18, 2021
@Progi1984 Progi1984 added the Waiting for QA Status: action required, waiting for test feedback label Jun 18, 2021
@Progi1984 Progi1984 added this to the 1.7.8.0 milestone Jun 18, 2021
@NeOMakinG NeOMakinG dismissed stale reviews from Progi1984 and PierreRambaud via 2bc02a3 June 18, 2021 13:03
@NeOMakinG NeOMakinG removed the Waiting for QA Status: action required, waiting for test feedback label Jun 18, 2021
@Progi1984 Progi1984 added the Waiting for QA Status: action required, waiting for test feedback label Jun 18, 2021
@NeOMakinG
Copy link

@MatShir so we need to focus develop on this PR?

@MatShir
Copy link
Contributor

MatShir commented Jun 22, 2021

@Progi1984 @NeOMakinG, friendly reminder, in a beta phase to avoid new bugs and to stabilize the software, we don't accept improvements. Could you please transfer the contribution into develop please ?
And the improvement is applied to the new product page, which is hidden on the feature flag, so It can wait for the next version :)

@NoZTurn, thanks a lot for the improvements. It is very appreciated, but it is not on the right branch 😄

@Robin-Fischer-PS Robin-Fischer-PS removed the Waiting for QA Status: action required, waiting for test feedback label Jun 22, 2021
@Robin-Fischer-PS Robin-Fischer-PS added Waiting for author Status: action required, waiting for author feedback Waiting for dev Status: action required, waiting for tech feedback labels Jun 22, 2021
@NeOMakinG
Copy link

@NoZTurn we need to do these changes on the develop branch.

The rebase is a bit hardcore, so I would suggest you to cherry pick commits into a new PR based on develop, don't hesitate if you need help. I could do it, but it's your work and I don't wan't to steal it :)

NoZTurn added a commit to NoZTurn/PrestaShop that referenced this pull request Jun 22, 2021
Questions	Answers
Branch?	develop
Description?	with this small code trick ,we can change the replaced image to the newest one immediately the time after the image ajax replaced without the page refresh or reload.
Type?	improvement
Category?	BO
BC breaks?	no
Deprecations?	no
Fixed ticket?	Fixes #{20035}.
How to test?	Just clear your caches and refresh your product v2 page.
Possible impacts?	small change, no other impact.
@NoZTurn
Copy link
Contributor Author

NoZTurn commented Jun 22, 2021

@MatShir @NeOMakinG thanks for your sugguestion, and I have submit this pull request to the develop branch here #25089.

@NeOMakinG
Copy link

Closing in favor of #25089. Thanks @NoZTurn

@NeOMakinG NeOMakinG closed this Jun 23, 2021
@NoZTurn NoZTurn deleted the 1.7.8.x branch June 29, 2021 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.7.8.x Branch Improvement Type: Improvement Waiting for author Status: action required, waiting for author feedback Waiting for dev Status: action required, waiting for tech feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvement - being able to replace an existing image in product sheet page
7 participants