Skip to content

Conversation

@ihor-sviziev
Copy link
Contributor

@ihor-sviziev ihor-sviziev commented Jul 23, 2018

Description

I investigated issue described in #16568 and found that we have 2 different polyfill implementaions for localStorage and sessionStorage:

  1. Added to page html (https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Theme/view/frontend/templates/js/polyfill.phtml)
  2. As part of jquery.storageapi library - https://github.com/magento/magento2/blob/2.2-develop/lib/web/jquery/jquery.storageapi.min.js

These implementation are fully different. 1st one works good, but 2nd one adds strange behavior - adds separate cookie with ls_ prefix in name for each item that should be stored in localstorage and ss_<some_id>_ for session storage. As result - when customer goes through website - it will add new and new cookies (because of this strange ss_<some_id>_ prefix).

For some reasons sometimes, probably because of race conditions, we're having 2nd implementation used instead of 1st one.

This PR moving 1st implementation into head section (before requirejs), so it will be loaded first for sure.

Also it doing partial backport of #14318 to 2.2-develop branch in order not to add backward incompatible changes.

Fixed Issues (if relevant)

  1. local/session storage is mismanaged, particularly when it doesn't exist #16568: local/session storage is mismanaged, particularly when it doesn't exist
  2. Unable to send the cookie. Maximum number of cookies would be exceeded #7931: Unable to send the cookie. Maximum number of cookies would be exceeded
  3. Incorrect message: Unable to send the cookie. Maximum number of cookies would be exceeded #17195: Unable to send the cookie. Maximum number of cookies would be exceeded

Related Pull Requests

  1. Update Cookie Manager library to make max cookie number configurable #10516: Update Cookie Manager library to make max cookie number configurable
  2. Update cookie limit to 300 #10961: Update cookie limit to 300

Manual testing scenarios

  1. N/A

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 on Travis CI are green)

jonathanKingston and others added 3 commits July 23, 2018 16:55
…the head block.

Apply changes from lib/web

(cherry picked from commit 823f07a)
…the head block.

Apply changes in  Magento_Theme module (cherry picked from commit 823f07a)
…the head block.

Apply changes in  Magento_Theme module (cherry picked from commit 823f07a)
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev. Thank you for your contribution
Here is 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-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me {$VERSION} instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@ihor-sviziev ihor-sviziev changed the title [Backport/Bugfix] Move polyfill JavaScript code to be included as a remote script from the head block [Backport + Bugfix] Move polyfill JavaScript code to be included as a remote script from the head block Jul 23, 2018
…the head block.

- Add block back
- Drop original content from polyfill.phtml
…the head block.

- Add copyright and description to polyfill.js file
@ihor-sviziev ihor-sviziev force-pushed the move-polifill-js-code-2.2 branch from fed37e7 to c9f67f2 Compare July 23, 2018 15:25
@VladimirZaets VladimirZaets self-assigned this Jul 25, 2018
@VladimirZaets
Copy link
Contributor

Hi @ihor-sviziev, thank for collaboration. I think we can remove template attribute from the head.polyfill block declaration at all. What do you think?

@ihor-sviziev
Copy link
Contributor Author

ihor-sviziev commented Jul 27, 2018

Hi @VladimirZaets,
Good idea.

However we found an issue with current implementation in Safari and Firefox with disabled localstorage support. We're getting an error "Error: Attempted to assign to readonly property.".

After this issue all another JS files (including magento components) just doesn't work.

Related issues (with localstorage polyfills): mortzdk/localStorage#1 https://gist.github.com/orion110217/ef26968000df7290de03a8f774b46b79#gistcomment-2316288

Looks like fix will be much harder than I thought.

PS: We were able to reproduce issue #16568 by disabling localstorage in Firefox and applying this patch.

@ihor-sviziev
Copy link
Contributor Author

@magento-engcom-team give me 2.2.5 instance

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev. Thank you for your request. I'm working on Magento 2.2.5 instance for you

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, here is your Magento instance.
Admin access: https://i-17033-2-2-5.engcom.dev.magento.com/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@ihor-sviziev
Copy link
Contributor Author

ihor-sviziev commented Jul 27, 2018

I found really good steps to reproduce. Described them in #17195

@ihor-sviziev
Copy link
Contributor Author

ihor-sviziev commented Aug 7, 2018

We had long discussion with @VladimirZaets in slack and decided that following changes can't fix the issue.

We found following things:

  1. polyfill js doesn't work correctly because window.localStorage is read only. As a workaround we could use another variable name.
  2. jquery.storageapi.js library contains a lot of issues and we can't fix them in 2.2 release line as it will be backward incompatible change
  3. as jquery.storageapi.js library contains a lot of issue and it's not supporting anymore - it's better to replace this library with another one as part of 2.3 release line

I'm closing this PR as it's not fixing real issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants