Closed (fixed)
Project:
Webform
Version:
8.x-5.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
28 Jul 2020 at 22:00 UTC
Updated:
20 Aug 2020 at 09:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
luke.leberComment #3
luke.leberComment #4
luke.leberComment #5
luke.leberComment #6
luke.leberComment #7
luke.leberComment #8
luke.leberFix broken variants tests.
Comment #9
luke.leberComment #10
luke.leberComment #11
luke.leberComment #12
luke.leberActually, the local storage needs to be scoped to the webform as well.
Comment #13
jrockowitz commentedI think this is a design mistake, and a randomly selected variant should always persist for the user's entire session. Variants are still considered experimental, and we can make this improvement.
We might only need to commit some variation of the code in
_webform_page_attachments?Right now, the Webform module's JavaScript is not using ES6 and instead of using
letfor variable declariation, we probably need continue to usevar.If the Webform module moves to ES6, we should update all the JS code.
Comment #14
jrockowitz commentedWe might also need to adjust the label/description for the 'Randomly load variant' checkbox.
Comment #15
luke.leberPatch includes just a Javascript tweak.
I did not test the JS on obscure configurations like IE, private windows, and customized browser settings related to storage. I'll try to do extensive testing after hours today.
Safe cross browser storage access is a minefield.
Comment #16
jrockowitz commentedIdeally, we should be able to convert \Drupal\Tests\webform\Functional\Variant\WebformVariantRandomizeTest to JavaScript Test and check that the randomized variant persists.
Comment #17
luke.leberExamining
\Drupal\Tests\webform\Functional\Variant\WebformVariantRandomizeTest, I now wonder whether we need to update session storage if a stored variant no longer exists.Taking the scenario from the test, if a user has variant 'A' stored locally and the site owner disables 'A', then should the user transition to use another random variant? Likewise, if all variants are disabled (for example, if the A/B test concludes), should the local storage be cleared out for the variant?
Comment #18
jrockowitz commentedI think the new code needs to add session handling in two steps, load and then save.
Comment #19
jrockowitz commentedBTW, you might need to create getSessionVariantID and setSessionVariantID helper functions to make the code more manageable.
Comment #20
luke.leberDoes this get things moving in the right direction?
Note - I still have yet to perform device testing on the JS. After a good looking patch emerges, I can run through some Browserstack testing on various devices.
Comment #21
luke.leberForgot to remove the old Functional test.
Comment #22
luke.leberComment #23
luke.leberI can't really explain those
webform_groupfailures. May be related to https://www.drupal.org/project/group/releases/8.x-1.1 that came out yesterday?Comment #24
jrockowitz commentedAttached patch has minor improvements
Comment #25
jrockowitz commentedDarn the "Composer require-dev failure" is a DrupalCI issue that is being worked on. I already bothered Neil Drumm. I am going to wait until next Monday to nudge Neil. I might be able to fix it by pushing a commit to 8.x-5.x over the weekend.
Comment #26
luke.leberI'll do some browserstack device testing later on tonight and report back.
Comment #27
luke.leberResults from device testing:
The windows phone configuration didn't seem to redirect to any variants. I'm not quite sure why, as dev tools are unavailable with that configuration.
#24 looks A-OK to me!
Comment #28
luke.leberComment #29
luke.leberActually...I tried one other test variation and got a somewhat unexpected result!
Toggling off cookie storage in Google Chrome results in:
It looks like the
if (window.sessionStorage)...expression is throwing an exception (Chrome 84). As a result, the redirect doesn't function at all.I'm not sure if this constitutes an unacceptable condition or not. Anyone that blocks cookies and such these days on the web should be fairly used to a sub-par user experience as it is.
Comment #30
luke.leberComment #31
jrockowitz commentedI think Chrome is working as expected. In webform.element.message.js, we are just checking for the window.sessionStorage and we probably should just repeat the same approach here
@see https://git.drupalcode.org/project/webform/-/blob/8.x-5.x/js/webform.ele...
We can probably change...
if (typeof(window.sessionStorage) === 'undefined') {...to...
if (!window.sessionStorage) {Comment #32
jrockowitz commentedTo address "Uncaught DOMException: Failed to read the 'sessionStorage' property from 'Window'" all calls to localStorage and sessionStorage must be wrapped in a try/catch statement. I am not sure we even need to keep the
if (window.sessionStorage) {}statementshttps://stackoverflow.com/questions/58152236/what-to-do-when-sessionstor...
The attached patch address all calls to localStorage and sessionStorage.
Comment #33
jrockowitz commentedI did a little more research and found this article.
https://mathiasbynens.be/notes/localstorage-pattern
I would lean toward using the Modernizer approach.
Comment #34
luke.leberThis almost seems like something that should be bundled into a library to be reused everywhere in the module (this might even be a candidate for a core feature, honestly). There seems to be a lot of boilerplate involved in "safely" accessing storage (localStorage + sessionStorage).
I can test out the Modernizr approach with this issue on different devices and see how it goes, but I probably won't have time to update the patch and give it a drive until at least tomorrow evening.
Comment #35
jrockowitz commentedI looked through Drupal core and there is no exception handling around localStorage or sessionStorage. For now, I would be okay with including the Modernizr approach escapsulted within each JS file as needed. Right now, there is no dedicated generic JS library webform file .
Comment #36
jrockowitz commentedComment #37
luke.leberTested #36 against Safari on iOS 11 (Browserstack) + Chrome 84 with storage disabled - looks good!
Going to move to RTBC pending test runner. Thanks!
Comment #38
luke.leberComment #41
jrockowitz commented