9

We have a packaged lightning component for use in communities that uses a cookie to track some properties about unauthenticated users between page visits. In my DE org, Locker Service has no support for document.cookie. I know that the lightning team had mentioned that support was on the roadmap but the critical update for communities goes live very soon and this is not yet available in my org and I see that in the aura source code, SecureDocument.cookie is still read-only.

Is document.cookie read/write support going to be available in Locker Service before the critical update activation date of 2/11/2017 or do we have to refactor our application to use localStorage (assuming this is available) before that date and get all of our customers to update?

Obviously we would love not to spend all the resources on refactoring the application to work around the missing document.cookie support but the tracking functionality is critical and having our application suddenly go down on 2/11/2017 would be unacceptable.

  • You may want to file a case for this feature – Robert Sussland Jan 3 '17 at 21:30
  • @RobertSussland I wish I could, but I do not have premier support so my cases related to development or platform features get closed as out of scope. – dsharrison Jan 3 '17 at 21:44
  • Where are you getting the 2/11/2017 date from? If you check the "Lightning LockerService" setup page you'll see Locker won't be auto-activated without the option to disable until Summer '17, which isn't scheduled to be released to production until June '17. – TrevorBliss Jan 11 '17 at 18:27
  • Ah I see, the Communities Critical Update for LockerService originally said 2/11/2017. This Critical Update is being merged with the standard LockerService Critical Update in Spring '17 and the date is 6/13/2017. A little more time to get things hashed out and tested. – TrevorBliss Jan 11 '17 at 18:48
11
+100

Support for document.cookie being writable (scoped to your own namespace, similar to how localStorage and sessionStorage work in Locker) is at the top of our queue and (Safe Harbor :p) is planned to be released before the auto-activation date to give you time to verify functionality.

I'll update this answer as progress is made.

Edit (Feb 13, 2017): Read/write support inside LockerService for cookies is currently scheduled to be released in a patch next week (Safe Harbor). Please note that you will only be able to read cookies your own namespace has written. Cookies created from other origins will be hidden inside your Lightning components.

  • 1
    Thanks for the update! Merging those two critical update dates is a huge help for our team since we can focus our efforts on our whole app instead of just scrambling on the communities aspect right now. The release date is still 2/11/2017 in my existing org but I see that the communities specific update is removed in my spring '17 org. – dsharrison Jan 11 '17 at 19:01
  • @D.S. See my edit to the answer above. – TrevorBliss Feb 13 '17 at 21:45
  • Thanks for the update. Is there planned support for accessing these cookies from Visualforce as well? Some of our customers use communities that have a mix of the Lightning Template and some Visualforce pages. We could just consume the schema that you guys set up but if that were to change we would be out of luck. – dsharrison Feb 14 '17 at 19:04
  • I have been reviewing the localStorage implementation with my team with the assumption that cookies will be implemented in a similar way. We have one big question regarding the namespace and that is: Will we be able to see cookies in our lightning component that were written via the ApexPages.currentPage().setCookies() from our namespace on a Visualforce page in the same community? – dsharrison Feb 22 '17 at 20:30
  • @D.S. This change is now released to all orgs so you can try it out yourself. How it works is the Lightning component inside Locker will only have access to cookies created from other Lightning components in it's own namespace. ApexPages.currentPage().getCookies() and scripts in VF pages don't have the same restriction and can see cookies set by the component (with a special prefix appended), but it doesn't go the other way so the Lightning component can't see cookies set by Apex/VF. – TrevorBliss Feb 23 '17 at 3:13
7

Support for read/write has been added to Locker Service by Salesforce (thanks to @TrevorBliss for following up on that). However, the implementation does not work the same way as before Locker Service if your community uses a mix of Lightning and Visualforce. For example, if you have some pages that serve Visualforce PDF files, these pages will not have access to the cookies set by your Lightning Components (and vice-versa if your Visualforce pages are setting cookies using the Apex Cookie class.

This is a deal-breaker for me because we have a lot of back-end functionality built that expects those guest session cookies to be there in both contexts. To deal with this I have implemented a simple page to allow cookies to be transferred between Lightning and Visualforce formats.

If you are running into the same problem you can find the files at: https://gist.github.com/dsharrison/a417db2917f6238a1c386063e1c5d133.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.