Session erroneously getting set to NULL on Drupal user login
Anonymous sessions may contain data that needs to be retained after login, for example commerce cart data. In the initialize() method of the core session class civicrm/civicrm-core/CRM/Core/Session.php, there is a check for a changed session id, which if it evaluates to TRUE will set a current session with data to NULL.
// remove $_SESSION reference if session is changed
if (($sid = session_id()) !== $this->sessionID) {
$this->_session = NULL;
$this->sessionID = $sid;
}
I've tested this with Drupal 9.2.4 CiviCRM 5.35 and Drupal Commerce 2.26. This specific change was added in #98 (closed) for Drupal 7.