mnfst 0.5.337 → 0.5.339

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1984,9 +1984,11 @@ function initializeTeamsCore() {
1984
1984
 
1985
1985
  // Load deleted template roles for current team (if roles defaults module is loaded)
1986
1986
  if (this.currentTeam && this.currentTeam.$id && window.ManifestAppwriteAuthTeamsRolesDefaults && this.getDeletedTemplateRoles) {
1987
- const deletedTemplateRoles = await this.getDeletedTemplateRoles(this.currentTeam.$id);
1987
+ const rolesTeamId = this.currentTeam.$id;
1988
+ const deletedTemplateRoles = await this.getDeletedTemplateRoles(rolesTeamId);
1988
1989
  if (stale()) return discarded;
1989
- this.deletedTemplateRoles = deletedTemplateRoles;
1990
+ // Another team may have been viewed meanwhile; its own load owns this
1991
+ if (this.currentTeam?.$id === rolesTeamId) this.deletedTemplateRoles = deletedTemplateRoles;
1990
1992
  }
1991
1993
 
1992
1994
  // Set currentTeam to first default team if available and not already set
@@ -1996,32 +1998,31 @@ function initializeTeamsCore() {
1996
1998
  (appwriteConfig?.templateTeams && Array.isArray(appwriteConfig.templateTeams) && appwriteConfig.templateTeams.length > 0);
1997
1999
 
1998
2000
  if (stale()) return discarded;
2001
+ // A team the app viewed during these awaits wins over the default pick
1999
2002
  if (hasDefaultTeams && window.ManifestAppwriteAuthTeamsDefaults && this.getDefaultTeams) {
2000
2003
  const defaultTeams = await this.getDefaultTeams();
2001
2004
  if (stale()) return discarded;
2002
- if (defaultTeams.length > 0) {
2003
- this.currentTeam = defaultTeams[0];
2004
- } else {
2005
- this.currentTeam = this.teams[0];
2006
- }
2007
- } else {
2005
+ if (!this.currentTeam) this.currentTeam = defaultTeams.length > 0 ? defaultTeams[0] : this.teams[0];
2006
+ } else if (!this.currentTeam) {
2008
2007
  this.currentTeam = this.teams[0];
2009
2008
  }
2010
2009
  }
2011
2010
 
2012
2011
  // Auto-load memberships for current team (if members module is loaded)
2013
2012
  if (this.currentTeam && this.currentTeam.$id && window.ManifestAppwriteAuthTeamsMembers && this.listMemberships) {
2013
+ // Written only while that team is still current: a viewTeam meanwhile owns the list
2014
+ const membersTeamId = this.currentTeam.$id;
2014
2015
  try {
2015
- const membershipsResult = await this.listMemberships(this.currentTeam.$id);
2016
+ const membershipsResult = await this.listMemberships(membersTeamId);
2016
2017
  if (stale()) return discarded;
2017
- if (membershipsResult.success) {
2018
+ if (membershipsResult.success && this.currentTeam?.$id === membersTeamId) {
2018
2019
  this.currentTeamMemberships = membershipsResult.memberships || [];
2019
2020
  }
2020
2021
  } catch (error) {
2021
2022
  // Silently handle errors (e.g., team was deleted)
2022
2023
  // listMemberships already handles "team not found" gracefully
2023
2024
  if (stale()) return discarded;
2024
- this.currentTeamMemberships = [];
2025
+ if (this.currentTeam?.$id === membersTeamId) this.currentTeamMemberships = [];
2025
2026
  }
2026
2027
  }
2027
2028
 
@@ -2151,8 +2152,8 @@ function initializeTeamsCore() {
2151
2152
  // Use Alpine's nextTick if available to ensure reactivity is triggered
2152
2153
  if (typeof Alpine !== 'undefined' && Alpine.nextTick) {
2153
2154
  Alpine.nextTick(() => {
2154
- // Ensure the update is visible
2155
- this.currentTeam = refreshedTeam;
2155
+ // Ensure the update is visible, unless another team was viewed meanwhile
2156
+ if (this.currentTeam?.$id === teamId) this.currentTeam = refreshedTeam;
2156
2157
  });
2157
2158
  }
2158
2159
  }
@@ -4967,8 +4968,8 @@ function initializeTeamsMembers() {
4967
4968
  this._updatingMember = membershipId;
4968
4969
  this.error = null;
4969
4970
 
4970
- // Optimistically update the UI immediately
4971
- if (this.currentTeamMemberships && Array.isArray(this.currentTeamMemberships)) {
4971
+ // Optimistically update the UI immediately (only the current team's list is shown)
4972
+ if (this.currentTeam?.$id === teamId && this.currentTeamMemberships && Array.isArray(this.currentTeamMemberships)) {
4972
4973
  const membershipIndex = this.currentTeamMemberships.findIndex(m => m.$id === membershipId);
4973
4974
  if (membershipIndex >= 0) {
4974
4975
  // Optimistically update membership with new roles
@@ -5103,8 +5104,8 @@ function initializeTeamsMembers() {
5103
5104
  this._deletingMember = membershipId;
5104
5105
  this.error = null;
5105
5106
 
5106
- // Optimistically remove member from UI immediately
5107
- if (this.currentTeamMemberships && Array.isArray(this.currentTeamMemberships)) {
5107
+ // Optimistically remove member from UI immediately (only the current team's list is shown)
5108
+ if (this.currentTeam?.$id === teamId && this.currentTeamMemberships && Array.isArray(this.currentTeamMemberships)) {
5108
5109
  this.currentTeamMemberships = this.currentTeamMemberships.filter(m => m.$id !== membershipId);
5109
5110
  }
5110
5111
 
@@ -5554,6 +5555,11 @@ function initializeTeamsConvenience() {
5554
5555
  if (result.success && this.currentTeam?.$id === team.$id) {
5555
5556
  this.currentTeamMemberships = result.memberships || [];
5556
5557
  }
5558
+ // Deleted template roles are per team too (shared prefs read, no extra request)
5559
+ if (this.getDeletedTemplateRoles && window.ManifestAppwriteAuthTeamsRolesDefaults) {
5560
+ const deleted = await this.getDeletedTemplateRoles(team.$id);
5561
+ if (this.currentTeam?.$id === team.$id) this.deletedTemplateRoles = deleted;
5562
+ }
5557
5563
  }
5558
5564
  return { success: true };
5559
5565
  };
@@ -6105,7 +6111,8 @@ function initializeTeamsConvenience() {
6105
6111
  }
6106
6112
  // Update available permissions for autocomplete
6107
6113
  if (this.getAllAvailablePermissions && team && team.$id) {
6108
- this.allAvailablePermissions = await this.getAllAvailablePermissions(team.$id);
6114
+ const available = await this.getAllAvailablePermissions(team.$id);
6115
+ if (this.currentTeam?.$id === team.$id) this.allAvailablePermissions = available;
6109
6116
  }
6110
6117
  return result;
6111
6118
  };