Skip to content

mageSwatchRenderer is undefined on PDP #36937

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

Open
1 of 5 tasks
Mugentoki opened this issue Mar 1, 2023 · 27 comments
Open
1 of 5 tasks

mageSwatchRenderer is undefined on PDP #36937

Mugentoki opened this issue Mar 1, 2023 · 27 comments
Assignees
Labels
Area: Product Component: Console Component: Framework/Console Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: needs update Additional information is require, waiting for response Priority: P3 May be fixed according to the position in the backlog. Progress: dev in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@Mugentoki
Copy link

Mugentoki commented Mar 1, 2023

Preconditions and environment

  • Magento version: 2.4.5-p2
  • Clean installation with demo data
  • Blank or Luma theme

Steps to reproduce

After setting up the fresh M2 instance with demo data

  1. Go to any product with swatches (size, color)
  2. In developer console, try to access the swatch renderer with
    jQuery('[data-role=swatch-options]').data('mageSwatchRenderer')

Expected result

Swatch renderer should be initialized and data be accessible
image

Actual result

Swatch renderer is undefined
image

Additional information

I still had a clean installed M2 version 2.3.4 around, and there it's working just fine.

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 Mar 1, 2023

Hi @Hoargarth. Thank you for your report.
To speed up processing of this issue, 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:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ 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.

@Mugentoki
Copy link
Author

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @Hoargarth. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Hi @Hoargarth, here is your Magento Instance: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering
Admin access: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering/admin_2da3
Login: 2844ce62
Password: 9bf9e8dce4ed

@engcom-Dash engcom-Dash self-assigned this Mar 1, 2023
@m2-assistant
Copy link

m2-assistant bot commented Mar 1, 2023

Hi @engcom-Dash. 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).
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    1. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. 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!

@Mugentoki
Copy link
Author

Checked on the radiant-tee /radiant-tee.html
And can reproduce the issue

image

@Mugentoki
Copy link
Author

There's this file in vendor vendor/magento/module-swatches/view/frontend/web/js/configurable-customer-data.js which is referencing mageSwatchRenderer

    var selectors = {
            formSelector: '#product_addtocart_form',
            swatchSelector: '.swatch-opt'
        },
        swatchWidgetName = 'mageSwatchRenderer',
        widgetInitEvent = 'swatch.initialized',




However, further inspecting the jQuery object in browser I can see it's actually attached with mage-SwatchRenderer and can be accessed like that jQuery('[data-role=swatch-options]').data('mage-SwatchRenderer')

image


So the question now arises, which one is correct?
mageSwatchRenderer or mage-SwatchRenderer

@engcom-Dash
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

@engcom-Dash engcom-Dash added the Reported on 2.4.x Indicates original Magento version for the Issue report. label Mar 2, 2023
@engcom-Dash
Copy link
Contributor

Hi @Hoargarth ,

Thanks for Raising this issue,

Could you please provide the exact steps which you followed for this issue.Because it will helps to proceed further in this case.

Thanks.

@engcom-Dash engcom-Dash added the Issue: needs update Additional information is require, waiting for response label Mar 2, 2023
@Mugentoki
Copy link
Author

Mugentoki commented Mar 3, 2023

Hi @engcom-Dash

First of all, I've lowered the severity to S3 as it's not affecting the store user, but us developers.

Detailed steps below:

  1. In frontend, go to the product page of any product, which has a size and/or color
  2. Open your browsers developer toolbar and go to the developer console
  3. Input following JavaScript into the console jQuery('[data-role=swatch-options]').data('mageSwatchRenderer')

The problem is not limited to the developer toolbar, but also happens when trying to access the 'mageSwatchRenderer' module by code in any .phtml or .js file. For example if you want to extract the selected product ID like it's being described in this article and was working at least until Magento 2.4.0

Also as I mentioned in my previous comment, I could already debug it a bit.

@engcom-Dash
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

@engcom-Dash
Copy link
Contributor

Hi @Hoargarth ,

Verified the issue is 2.4-develop instance and the issue is reproducible.

Description:
mageSwatchRenderer is undefined on PDP

Prerequisite:

Magento Version 2.4-develop
PHP Version 8.1

Actual result:
Swatch renderer should be initialized and data be accessible

Expected Result:
Swatch renderer is undefined

Steps to reproduce:
1.In frontend, go to the product page of any product, which has a size and/or color
2.Open your browsers developer toolbar and go to the developer console
3.Input following JavaScript into the console jQuery('[data-role=swatch-options]').data('mageSwatchRenderer')

Screenshots for your reference:
unde1

We are getting Actual result which is Swatch renderer is undefined ,Hence we are confirming the issue in 2.4-develop instance.

Let us know if we are missing anything

Thanks,

@engcom-Dash engcom-Dash removed their assignment Mar 6, 2023
@engcom-Dash engcom-Dash added Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it and removed Issue: needs update Additional information is require, waiting for response labels Mar 6, 2023
@engcom-November engcom-November self-assigned this Mar 6, 2023
@m2-assistant
Copy link

m2-assistant bot commented Mar 6, 2023

Hi @engcom-November. 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).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas 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-November engcom-November added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: Framework/Console Component: Console labels Mar 7, 2023
@engcom-November engcom-November added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Product labels Mar 7, 2023
@github-jira-sync-bot
Copy link

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

@m2-assistant
Copy link

m2-assistant bot commented Mar 7, 2023

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

@engcom-November engcom-November added the Priority: P3 May be fixed according to the position in the backlog. label Mar 7, 2023
@engcom-November engcom-November removed 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 labels Mar 7, 2023
@engcom-November engcom-November self-assigned this Mar 7, 2023
@engcom-November
Copy link
Contributor

Hi @Hoargarth ,
Thank you for the response. I re-checked the issue on latest Magento 2.4-develop instance and verified the code in /Swatches/view/frontend/web/js/configurable-customer-data.js and is mentioned as swatchWidgetName = 'mage-SwatchRenderer' but not mageSwatchRenderer also data is displayed in console on verifying with mage-SwatchRenderer
image
Kindly recheck the code on Magento 2.4-develop instance as it is having latest code base and upcoming 2.4.x release and let us know if you are still facing any issues.
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Swatches/view/frontend/web/js/configurable-customer-data.js
Thank you.

@engcom-November engcom-November added Issue: needs update Additional information is require, waiting for response Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch labels Mar 7, 2023
@Mugentoki
Copy link
Author

Hi @engcom-November
since https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Swatches/view/frontend/web/js/configurable-customer-data.js is now also using mage-SwatchRenderer, I assume the change from mageSwatchRenderer was intended?

If so, then this issue can be closed.
But I highly recommend to add a documentation about the change somewhere in the docs. Many blog articles are referencing mageSwatchRenderer

@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 14, 2023

mage-SwatchRenderer is correct widget name -> you should use that name

@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 16, 2023

@dobooth
Is there any docs official related with this area ? mageSwatchRenderer
In my opinion other blog also should update code snippets to latest version. I don't sure current docs mention this somewhere

@engcom-November
Copy link
Contributor

Hi @Hoargarth ,
There is no official Magento documentation referring this topic in devdocs & docs to raise an issue report in https://github.com/magento/devdocs or https://github.com/magento/merchdocs repositories to update the changes. Please share the official articles that are are referencing mageSwatchRenderer if any.
Thank you.

@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 17, 2023

@engcom-Hotel engcom-Hotel moved this to Dev In Progress in Low Priority Backlog Aug 19, 2024
ahmed-jafri added a commit to ahmed-jafri/swissup.github.io that referenced this issue Nov 6, 2024
mageSwatchRenderer was in old versions of Magento. So the accessing the swatch rendered was causing an 'undefined' error. Upon checking the code (with references from magento/magento2#36937), replacing mageSwatchRenderer with mage-SwatchRenderer fixes the issue.
ahmed-jafri added a commit to ahmed-jafri/swissup.github.io that referenced this issue Nov 26, 2024
mageSwatchRenderer was in old versions of Magento. So the accessing the swatch rendered was causing an 'undefined' error. Upon checking the code (with references from magento/magento2#36937), replacing mageSwatchRenderer with mage-SwatchRenderer fixes the issue.
@engcom-November
Copy link
Contributor

Hello @Mugentoki ,

Thank you for the report and collaboration,

We attempted to reproduce the issue in our latest version 2.4 develop but were unable to do reproduce it. Please find the attached screenshot for reference.

Image

Steps to Reproduce

  1. Go to any product with swatches (size, color)
  2. In developer console, try to access the swatch renderer with
    jQuery('[data-role=swatch-options]').data('mage-SwatchRenderer')

We followed these steps and did not encounter any issues. Could you please recheck in the latest version of Magento and let us know if we are missing any steps to reproduce this issue?

Therefore, we are marking this ticket as "Issue: Needs Update".

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Product Component: Console Component: Framework/Console Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: needs update Additional information is require, waiting for response Priority: P3 May be fixed according to the position in the backlog. Progress: dev in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

No branches or pull requests

5 participants