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

Magnifier.js syntax error #36200

Open
1 of 5 tasks
vandijkstef opened this issue Sep 26, 2022 · 16 comments · May be fixed by #39321
Open
1 of 5 tasks

Magnifier.js syntax error #36200

vandijkstef opened this issue Sep 26, 2022 · 16 comments · May be fixed by #39321
Assignees
Labels
Area: Framework Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: PR in progress Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@vandijkstef
Copy link

vandijkstef commented Sep 26, 2022

Preconditions and environment

  • Mage 2.4.4

Steps to reproduce

  1. Open the console on the Product Detail page and define const data={} in the console.
  2. Try to navigate the image gallery and get the below error:

image

3. But if replace `;` to `,` from `lib/web/magnifier/magnifier.js`, then the issue is resolved.

./lib/web/magnifier/magnifier.js 26-30 is causing an error depending on contexts

           largeWrapper = options.largeWrapper || '.magnifier-preview',
            $magnifierPreview = $(largeWrapper);

        curThumb = null,
        magnifierOptions = {

It errors out later in the script, saying I cannot redefine const data. This is because the list of variables starting at curThumb doesn't have specified what kind of var it is, thus living in global space.

So a fix would either be

// Comma instead of ;
$magnifierPreview = $(largeWrapper),
curThumb = null,

Or properly initiate the variables

$magnifierPreview = $(largeWrapper);

var curThumb = null,

Expected result

No JS errors

Actual result

JS breaks, product detail page image gallery is not functional anymore.

Additional information

I wouldn't know which solution is preferred which is why I just drop this as an issue with possible solutions provided. Additionally, it would be great to have proper JS linting set up, that doesn't allow global variable declaration like this.

As far as I can see, this has been an issue/unchanged for a few Magento version, it just got triggered by another module/js taking 'control' of the 'data' var-label.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Sep 26, 2022

Hi @vandijkstef. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@engcom-Delta engcom-Delta added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Sep 26, 2022
@engcom-Delta engcom-Delta self-assigned this Sep 26, 2022
@m2-assistant
Copy link

m2-assistant bot commented Sep 26, 2022

Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Delta
Copy link
Contributor

Hi @vandijkstef,

Thank you for reporting and collaboration,

Can you please provide more detail on which context you are getting error.

Thanks.

@engcom-Delta engcom-Delta added the Issue: needs update Additional information is require, waiting for response label Sep 26, 2022
@vandijkstef
Copy link
Author

Hi @engcom-Delta,

Sorry I missed your question for a bit. Basically I have another js-script running that is trying to set a variable const data. The variable initialisation of the magnifier script is interupted by the ; on the line containing $magnifierPreview = $(largeWrapper); making every variable after it global, as it's not prefixed by var|let|const anymore.

Here's an interesting thread about the subject

@engcom-Delta engcom-Delta removed their assignment Oct 11, 2022
@engcom-Hotel
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Hotel. Thank you for your request. I'm working on Magento instance for you.

@engcom-Hotel engcom-Hotel self-assigned this Dec 13, 2022
@m2-assistant
Copy link

m2-assistant bot commented Dec 13, 2022

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@magento-deployment-service
Copy link

@engcom-Hotel
Copy link
Contributor

Hello @vandijkstef,

Thanks for the reporting and collaboration!

We have tried to reproduce the issue on the above Magento instance and found that curThumb variable is in the Global scope, please refer the screenshot:

image

But still, the Image gallery is working fine for us. Can you please let us know any additional steps which we need to follow in order to reproduce the issue?

Thanks

@vandijkstef
Copy link
Author

Basically I have another js-script running that is trying to set a variable const data.

curThumb is just the start of this list of global variables. Having global variables is just asking for unintended side-effects and incompatibility issues. Please stop using global variables. Any module (accidently) using one of these variable names will have issues.

It's highly likely to me that $magnifierPreview = $(largeWrapper); used to end with nothing, and a linter added ; to that line

@engcom-Hotel
Copy link
Contributor

Hello @vandijkstef,

Thanks for the reply!

According to your comment, we have tried to reproduce the issue by following the below steps:

  1. Open the console on the Product Detail page and define const data={} in the console.
  2. Try to navigate the image gallery and get the below error:

image

3. But if replace `;` to `,` from `lib/web/magnifier/magnifier.js`, then the issue is resolved.

But I think this is not the proper way to reproduce the issue. So can you please help us in the same?

Thanks

@vandijkstef
Copy link
Author

vandijkstef commented Dec 14, 2022

This is the proper way to reproduce this issue. This is the proper solution. It's all about JS coding standards not being applied here. Any of the following variables will not be usable by any other module

curThumb
magnifierOptions
pos
gId
status
curIdx
curLens
curLarge
lensbg
gZoom
gZoomMin
gZoomMax
gMode
gEventTypemagnifierOptions.eventType,
data
inBounds
isOverThumb
rate
paddingX
paddingY
enabled
showWrapper

If I look the the old version of the file (it's a few years back) you can see what was originally in there, and that a ; was inserted around here likely without the intend to do so, but a linter accidently inserting the ;

@engcom-Hotel
Copy link
Contributor

Hello @vandijkstef,

Thanks for the update!

We are confirming this issue and updating the main description with the steps mentioned here #36200 (comment)

Thanks

@engcom-Hotel engcom-Hotel added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Priority: P3 May be fixed according to the position in the backlog. Area: Framework labels Dec 15, 2022
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-7440 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Dec 15, 2022

✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@engcom-Hotel engcom-Hotel removed the Issue: needs update Additional information is require, waiting for response label Dec 15, 2022
@vandijkstef
Copy link
Author

This is still an issue in Mage 2.4.7 - We're talking about replacing a ; with a , after faulty auto-formatted js code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P3 May be fixed according to the position in the backlog. Progress: PR in progress Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Ready for Development
5 participants