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

Seperate js out template to avoid render issue #32434

Conversation

mrtuvn
Copy link
Contributor

@mrtuvn mrtuvn commented Mar 11, 2021

Description (*)

Main purpose of this PR to seperate js out of template avoid mix js-in-php

Previously if we set store to production with minify enabled. When access backend will raise error because phtml can't render properly

Browser screen return
"An error has happened during application run. See exception log for details."

Reference var/log/system.log

Here is the error log when we meet steps scenario
main.CRITICAL: ParseError: syntax error, unexpected '<<' (T_SL) in /var/www/html/var/view_preprocessed/pub/static/app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml:44
Stack trace:
0 /var/www/html/lib/internal/Magento/Framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php->render()
1 /var/www/html/generated/code/Magento/Backend/Block/Store/Switcher/Interceptor.php(428): Magento\Framework\View\Element\Template->fetchView()

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes magento/magento2#<issue_number>

Manual testing scenarios (*)

  1. Switch to production mode
    bin/magento deploy:mode:set production
  2. Run command to config minify html
    bin/magento config:set --lock-env dev/template/minify_html 1
  3. Clear cache and run deploy static content for backend area
  4. Navigate to admin and login with credentials

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Seperate js out template to avoid render issue #32454: Seperate js out template to avoid render issue

@m2-assistant
Copy link

m2-assistant bot commented Mar 11, 2021

Hi @mrtuvn. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests 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 Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

], function(jQuery, $t, confirm) {
'use strict';

(function($) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have feeling that it should be inside the return function(config) { .... What do you thing?

"useConfirm": <?= /* @noEscape */ $block->getUseConfirm(); ?>,
"isUsingIframe": <?= /* @noEscape */ $block->isUsingIframe(); ?>,
"switchUrl": "<?= $block->escapeUrl($block->getSwitchUrl()); ?>",
"storeId": <?= /* @noEscape */ $block->getStoreId(); ?>
Copy link
Contributor

Choose a reason for hiding this comment

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

I bevieve we should convert it to int before printing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified as your suggestion

@ihor-sviziev ihor-sviziev added the Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. label Mar 11, 2021
@mrtuvn mrtuvn force-pushed the move-admin-store-swticher-to-js branch from 57c95bd to 87c98a9 Compare March 11, 2021 07:48
@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Mar 11, 2021

@mrtuvn please add a reference to the following conversation c8a5013#commitcomment-48119352 in the description

Comment on lines 13 to 16
<arguments>
<argument name="is_using_iframe" xsi:type="string">0</argument>
</arguments>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain why you did it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This variable not set anywhere in code-base so i think we should declare it here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@mrtuvn mrtuvn Mar 11, 2021

Choose a reason for hiding this comment

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

Add default value here. Other modules core or 3rd-party providers extensions can easy override it via design area (adminhtml) by layout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setUseConfirm is unneccesary because it's already set via Block

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 48 to 117
confirm({
content: $t('Please confirm scope switching. All data that hasn\'t been saved will be lost.'),
actions: {
confirm: function () {
reload();
},
cancel: function () {
obj.value = config.storeId ? config.storeId : '';
}
}
});
Copy link
Contributor

@ihor-sviziev ihor-sviziev Mar 11, 2021

Choose a reason for hiding this comment

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

maybe that's a bit stupid question, but can we wrap it to require and load 'mage/translate' and 'Magento_Ui/js/modal/confirm' components when this really needed? It should a bit improve page load time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 13 to 16
<arguments>
<argument name="is_using_iframe" xsi:type="string">0</argument>
</arguments>
Copy link
Contributor

Choose a reason for hiding this comment

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

@mrtuvn mrtuvn force-pushed the move-admin-store-swticher-to-js branch 3 times, most recently from 119a2f1 to 80f6682 Compare March 11, 2021 09:22
Comment on lines 13 to 16
<arguments>
<argument name="use_confirm" xsi:type="string">1</argument>
<argument name="is_using_iframe" xsi:type="string">0</argument>
</arguments>
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like it won't work, as we don't have this argument in constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you can get it via Block class no problem by getData('variable')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ihor-sviziev ihor-sviziev added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Mar 11, 2021
@ihor-sviziev
Copy link
Contributor

Looks good to me. Let's wait for the test results.
Note: I don't think there is a way to cover this use case with automated tests, so I added a label that tests are not required.

@mrtuvn mrtuvn force-pushed the move-admin-store-swticher-to-js branch from 80f6682 to 895a386 Compare March 11, 2021 15:48
@sivaschenko
Copy link
Member

@magento create issue

@ihor-sviziev ihor-sviziev mentioned this pull request Mar 30, 2021
16 tasks
@gabrieldagama gabrieldagama added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. and removed Priority: P3 May be fixed according to the position in the backlog. labels Apr 6, 2021
@engcom-Oscar engcom-Oscar self-assigned this Apr 8, 2021
@m2-community-project m2-community-project bot added the Priority: P3 May be fixed according to the position in the backlog. label Apr 8, 2021
@engcom-Oscar
Copy link

✔️ QA passed

Was checked case from Manual testing scenarios

  1. Switch to production mode
    bin/magento deploy:mode:set production
  2. Run command to config minify html
    bin/magento config:set --lock-env dev/template/minify_html 1
  3. Clear cache and run deploy static content for backend area
  4. Navigate to admin and login with credentials

Before:
Screenshot from 2021-04-08 14-45-20

✔️ After:
Admin logged-in successfully
Screenshot from 2021-04-08 14-45-50

@m2-assistant
Copy link

m2-assistant bot commented Apr 11, 2021

Hi @mrtuvn, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Backend Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Type: Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] Seperate js out template to avoid render issue
7 participants