@jskit-ai/workspaces-web 0.2.36 → 0.2.38

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - A signed-out person opening a page no longer freezes the browser tab. The workspaces runtime started checking surface access while the router still sat on its start location `/`, before its opening navigation had finished, so in an app whose default surface needs sign-in it redirected that `/` to the default surface and cancelled the navigation to the page the person opened. Each cancelled navigation then ran the router's `afterEach`, which redirected again and cancelled the next one, in a loop of microtasks that never let the page render or answer (the tab stayed on its loading screen). The runtime now leaves the route alone until the opening navigation finishes, and its `afterEach` ignores navigations that failed: a cancelled, aborted or duplicate navigation leaves the route where it was, and the one that replaced it runs its own check.
5
6
  - Inviting, revoking an invite, changing a member's role and removing a member reload only the invites or the members, not the workspace's role catalogue too: the catalogue is configuration that does not change with them, and each members response already carries it. `useWorkspaceMembersActions` no longer takes `workspaceRolesView`.
6
7
  - The members screen loads its members and pending-invites lists 20 at a time, with a Load more button under each list while it has more. A refetch, such as a realtime change, reads every loaded page again. The members admin status adds `hasMoreMembers`, `isLoadingMoreMembers`, `hasMoreInvites` and `isLoadingMoreInvites`, and its actions add `loadMoreMembers` and `loadMoreInvites`. `useWorkspaceMembersPage` no longer passes the role catalog view to `useWorkspaceMembersActions`.
7
8
  - The members screen's invite-role and member-role fields are http-web's `SelectField`, bound to `loading` while the workspace's role catalog loads, so a stored role id never shows as text before its label; the members admin status says `isLoadingRoles`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/workspaces-web",
3
- "version": "0.2.36",
3
+ "version": "0.2.38",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -16,15 +16,15 @@
16
16
  "./locales/en.json": "./locales/en.json"
17
17
  },
18
18
  "dependencies": {
19
- "@jskit-ai/users-core": "0.2.27",
20
- "@jskit-ai/workspaces-core": "0.2.27"
19
+ "@jskit-ai/users-core": "0.2.29",
20
+ "@jskit-ai/workspaces-core": "0.2.29"
21
21
  },
22
22
  "peerDependencies": {
23
- "@jskit-ai/auth-web": "0.2.26",
24
- "@jskit-ai/http-web": "0.2.29",
25
- "@jskit-ai/kernel": "0.2.18",
26
- "@jskit-ai/shell-web": "0.2.24",
27
- "@jskit-ai/users-web": "0.2.36",
23
+ "@jskit-ai/auth-web": "0.2.27",
24
+ "@jskit-ai/http-web": "0.2.30",
25
+ "@jskit-ai/kernel": "0.2.19",
26
+ "@jskit-ai/shell-web": "0.2.25",
27
+ "@jskit-ai/users-web": "0.2.38",
28
28
  "@tanstack/vue-query": "^5.90.5",
29
29
  "vue": "^3.5.13",
30
30
  "vue-router": "^5.0.4",
@@ -1,3 +1,4 @@
1
+ import { START_LOCATION } from "vue-router";
1
2
  import { normalizeLowerText } from "@jskit-ai/kernel/shared/support/normalize";
2
3
  import {
3
4
  resolveSurfaceDefinitionFromPlacementContext,
@@ -231,6 +232,12 @@ function createBootstrapPlacementRouteGuards({
231
232
  }
232
233
 
233
234
  const currentRoute = router.currentRoute.value;
235
+ // Until the router finishes its opening navigation, its current route is the start location "/", not the page
236
+ // the person opened, and redirecting would cancel that navigation. The runtime's afterEach checks the page once
237
+ // the router is on it.
238
+ if (currentRoute === START_LOCATION) {
239
+ return;
240
+ }
234
241
  const currentFullPath = String(currentRoute.fullPath || "").trim();
235
242
  const currentPath = resolveRuntimePathname(currentRoute.path || "/");
236
243
  const currentComparablePath = currentFullPath || currentPath;
@@ -425,7 +425,12 @@ function createBootstrapPlacementRuntime({
425
425
  });
426
426
  cleanup.push(unsubscribePlacement);
427
427
 
428
- const removeAfterEach = router.afterEach(() => {
428
+ const removeAfterEach = router.afterEach((_to, _from, failure) => {
429
+ // A cancelled, aborted or duplicate navigation left the route where it was, and the navigation that replaced
430
+ // it runs its own afterEach. Redirecting again here would cancel that one too, endlessly.
431
+ if (failure) {
432
+ return;
433
+ }
429
434
  routeGuards.enforceSurfaceAccessForCurrentRoute();
430
435
  applyWorkspaceColorFromPlacementContext("route");
431
436
  enforceCurrentWorkspaceStatus();
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { resolveWorkspaceThemePalette } from "@jskit-ai/workspaces-core/shared/settings";
4
4
  import { ThemeSymbol } from "vuetify/lib/composables/theme.js";
5
+ import { createMemoryHistory, createRouter } from "vue-router";
5
6
  import { createVuetifyThemeController } from "./support/vuetifyThemeController.js";
6
7
  import {
7
8
  WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN,
@@ -967,3 +968,94 @@ test("bootstrap placement runtime handles unauthenticated errors and marks works
967
968
  assert.equal(runtime.getWorkspaceBootstrapStatus("acme"), WORKSPACE_BOOTSTRAP_STATUS_UNAUTHENTICATED);
968
969
  assert.equal(placementRuntime.getContext().workspace, null);
969
970
  });
971
+
972
+ /**
973
+ * A real router whose replace stops navigating after `limit` calls, so a redirect loop ends and the test can count it.
974
+ * Its pages load like an application's lazily imported ones, so every navigation takes several microtask turns.
975
+ */
976
+ function createLoopLimitedRouter({ limit = 20, guard = null } = {}) {
977
+ const page = { render: () => null };
978
+ const loadPage = () => Promise.resolve(page);
979
+ const router = createRouter({
980
+ history: createMemoryHistory(),
981
+ routes: ["/", "/home", "/ops", "/auth/login"].map((path) => ({ path, component: loadPage }))
982
+ });
983
+ if (guard) {
984
+ router.beforeEach(guard);
985
+ }
986
+ const replaceCalls = [];
987
+ const replace = router.replace.bind(router);
988
+ router.replace = (target) => {
989
+ replaceCalls.push(String(target));
990
+ return replaceCalls.length > limit ? Promise.resolve() : replace(target);
991
+ };
992
+ return { router, replaceCalls };
993
+ }
994
+
995
+ function createSignInSurfaceContext({ authenticated = false, opsOwner = true } = {}) {
996
+ return {
997
+ auth: { authenticated },
998
+ surfaceAccess: { opsowner: opsOwner },
999
+ surfaceAccessPolicies: {
1000
+ public: {},
1001
+ authenticated: { requireAuth: true },
1002
+ ops_owner: { requireAuth: true, requireFlagsAll: ["ops_owner"] }
1003
+ },
1004
+ surfaceConfig: {
1005
+ tenancyMode: "workspaces",
1006
+ defaultSurfaceId: "home",
1007
+ enabledSurfaceIds: ["home", "ops", "auth"],
1008
+ surfacesById: {
1009
+ home: { id: "home", enabled: true, pagesRoot: "home", routeBase: "/home", requiresWorkspace: false, accessPolicyId: "authenticated" },
1010
+ ops: { id: "ops", enabled: true, pagesRoot: "ops", routeBase: "/ops", requiresWorkspace: false, accessPolicyId: "ops_owner" },
1011
+ auth: { id: "auth", enabled: true, pagesRoot: "auth", routeBase: "/auth", requiresWorkspace: false, accessPolicyId: "public" }
1012
+ }
1013
+ }
1014
+ };
1015
+ }
1016
+
1017
+ test("bootstrap placement runtime leaves the opening navigation alone while the router still sits on its start location", async () => {
1018
+ const placementRuntime = createPlacementRuntimeStub();
1019
+ placementRuntime.setContext(createSignInSurfaceContext());
1020
+ // The shell sends a signed-out person from the signed-in home to sign in.
1021
+ const { router, replaceCalls } = createLoopLimitedRouter({
1022
+ guard: (to) => (to.path === "/home" ? "/auth/login?returnTo=/home" : true)
1023
+ });
1024
+ const runtime = createTestRuntime({ placementRuntime, router });
1025
+
1026
+ // Client providers boot just before app.use(router) starts the opening navigation to the page's own address,
1027
+ // so the runtime starts while router.currentRoute is still the start location "/", where nobody is.
1028
+ const initialized = runtime.initialize();
1029
+ const opening = router.push("/auth/login");
1030
+ await initialized;
1031
+ await opening;
1032
+ await router.isReady();
1033
+ await flushTasks();
1034
+
1035
+ assert.deepEqual(replaceCalls, []);
1036
+ assert.equal(router.currentRoute.value.fullPath, "/auth/login");
1037
+ });
1038
+
1039
+ test("bootstrap placement runtime does not redirect again when its own redirect is cancelled by a newer one", async () => {
1040
+ const placementRuntime = createPlacementRuntimeStub();
1041
+ placementRuntime.setContext(createSignInSurfaceContext({ authenticated: true }));
1042
+ const { router, replaceCalls } = createLoopLimitedRouter();
1043
+ const runtime = createTestRuntime({ placementRuntime, router });
1044
+ await runtime.initialize();
1045
+ await router.push("/ops");
1046
+ await router.isReady();
1047
+
1048
+ // The person loses the ops flag, and two bootstrap answers arrive together: each redirects to the home surface,
1049
+ // and the second cancels the first. The cancelled one must not start another redirect from the page it left.
1050
+ placementRuntime.setContext({ surfaceAccess: { opsowner: false } });
1051
+ const payload = { session: { authenticated: true, userId: "1" }, workspaces: [], permissions: [] };
1052
+ const first = runtime.applyBootstrapPayload({ request: createBootstrapRequest("/ops"), payload });
1053
+ const second = runtime.applyBootstrapPayload({ request: createBootstrapRequest("/ops"), payload });
1054
+ await Promise.all([first, second]);
1055
+ for (let turn = 0; turn < 5; turn += 1) {
1056
+ await flushTasks();
1057
+ }
1058
+
1059
+ assert.deepEqual(replaceCalls, ["/home", "/home"]);
1060
+ assert.equal(router.currentRoute.value.fullPath, "/home");
1061
+ });