@rangojs/router 0.0.0-experimental.7 → 0.0.0-experimental.70
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/AGENTS.md +9 -0
- package/README.md +942 -4
- package/dist/bin/rango.js +1689 -0
- package/dist/vite/index.js +4951 -930
- package/package.json +70 -60
- package/skills/breadcrumbs/SKILL.md +250 -0
- package/skills/cache-guide/SKILL.md +294 -0
- package/skills/caching/SKILL.md +93 -23
- package/skills/composability/SKILL.md +172 -0
- package/skills/debug-manifest/SKILL.md +12 -8
- package/skills/document-cache/SKILL.md +18 -16
- package/skills/fonts/SKILL.md +167 -0
- package/skills/hooks/SKILL.md +334 -72
- package/skills/host-router/SKILL.md +218 -0
- package/skills/intercept/SKILL.md +131 -8
- package/skills/layout/SKILL.md +100 -3
- package/skills/links/SKILL.md +92 -31
- package/skills/loader/SKILL.md +404 -44
- package/skills/middleware/SKILL.md +173 -34
- package/skills/mime-routes/SKILL.md +128 -0
- package/skills/parallel/SKILL.md +204 -1
- package/skills/prerender/SKILL.md +685 -0
- package/skills/rango/SKILL.md +85 -16
- package/skills/response-routes/SKILL.md +411 -0
- package/skills/route/SKILL.md +257 -14
- package/skills/router-setup/SKILL.md +210 -32
- package/skills/tailwind/SKILL.md +129 -0
- package/skills/theme/SKILL.md +9 -8
- package/skills/typesafety/SKILL.md +328 -89
- package/skills/use-cache/SKILL.md +324 -0
- package/src/__internal.ts +102 -4
- package/src/bin/rango.ts +321 -0
- package/src/browser/action-coordinator.ts +97 -0
- package/src/browser/action-response-classifier.ts +99 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +92 -64
- package/src/browser/history-state.ts +80 -0
- package/src/browser/intercept-utils.ts +52 -0
- package/src/browser/link-interceptor.ts +24 -4
- package/src/browser/logging.ts +55 -0
- package/src/browser/merge-segment-loaders.ts +20 -12
- package/src/browser/navigation-bridge.ts +296 -558
- package/src/browser/navigation-client.ts +179 -69
- package/src/browser/navigation-store.ts +73 -55
- package/src/browser/navigation-transaction.ts +297 -0
- package/src/browser/network-error-handler.ts +61 -0
- package/src/browser/partial-update.ts +328 -313
- package/src/browser/prefetch/cache.ts +206 -0
- package/src/browser/prefetch/fetch.ts +150 -0
- package/src/browser/prefetch/observer.ts +65 -0
- package/src/browser/prefetch/policy.ts +48 -0
- package/src/browser/prefetch/queue.ts +160 -0
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +112 -0
- package/src/browser/react/Link.tsx +230 -74
- package/src/browser/react/NavigationProvider.tsx +87 -11
- package/src/browser/react/context.ts +11 -0
- package/src/browser/react/filter-segment-order.ts +11 -0
- package/src/browser/react/index.ts +12 -12
- package/src/browser/react/location-state-shared.ts +95 -53
- package/src/browser/react/location-state.ts +60 -15
- package/src/browser/react/mount-context.ts +6 -1
- package/src/browser/react/nonce-context.ts +23 -0
- package/src/browser/react/shallow-equal.ts +27 -0
- package/src/browser/react/use-action.ts +29 -51
- package/src/browser/react/use-client-cache.ts +5 -3
- package/src/browser/react/use-handle.ts +30 -126
- package/src/browser/react/use-href.tsx +2 -2
- package/src/browser/react/use-link-status.ts +6 -5
- package/src/browser/react/use-navigation.ts +22 -63
- package/src/browser/react/use-params.ts +65 -0
- package/src/browser/react/use-pathname.ts +47 -0
- package/src/browser/react/use-router.ts +76 -0
- package/src/browser/react/use-search-params.ts +56 -0
- package/src/browser/react/use-segments.ts +80 -97
- package/src/browser/response-adapter.ts +73 -0
- package/src/browser/rsc-router.tsx +214 -58
- package/src/browser/scroll-restoration.ts +127 -52
- package/src/browser/segment-reconciler.ts +221 -0
- package/src/browser/segment-structure-assert.ts +16 -0
- package/src/browser/server-action-bridge.ts +510 -603
- package/src/browser/shallow.ts +6 -1
- package/src/browser/types.ts +141 -48
- package/src/browser/validate-redirect-origin.ts +29 -0
- package/src/build/generate-manifest.ts +235 -24
- package/src/build/generate-route-types.ts +39 -0
- package/src/build/index.ts +13 -0
- package/src/build/route-trie.ts +265 -0
- package/src/build/route-types/ast-helpers.ts +25 -0
- package/src/build/route-types/ast-route-extraction.ts +98 -0
- package/src/build/route-types/codegen.ts +102 -0
- package/src/build/route-types/include-resolution.ts +418 -0
- package/src/build/route-types/param-extraction.ts +48 -0
- package/src/build/route-types/per-module-writer.ts +128 -0
- package/src/build/route-types/router-processing.ts +618 -0
- package/src/build/route-types/scan-filter.ts +85 -0
- package/src/build/runtime-discovery.ts +231 -0
- package/src/cache/background-task.ts +34 -0
- package/src/cache/cache-key-utils.ts +44 -0
- package/src/cache/cache-policy.ts +125 -0
- package/src/cache/cache-runtime.ts +342 -0
- package/src/cache/cache-scope.ts +167 -309
- package/src/cache/cf/cf-cache-store.ts +571 -17
- package/src/cache/cf/index.ts +13 -3
- package/src/cache/document-cache.ts +116 -77
- package/src/cache/handle-capture.ts +81 -0
- package/src/cache/handle-snapshot.ts +41 -0
- package/src/cache/index.ts +1 -15
- package/src/cache/memory-segment-store.ts +191 -13
- package/src/cache/profile-registry.ts +73 -0
- package/src/cache/read-through-swr.ts +134 -0
- package/src/cache/segment-codec.ts +256 -0
- package/src/cache/taint.ts +153 -0
- package/src/cache/types.ts +72 -122
- package/src/client.rsc.tsx +3 -1
- package/src/client.tsx +105 -179
- package/src/component-utils.ts +4 -4
- package/src/components/DefaultDocument.tsx +5 -1
- package/src/context-var.ts +156 -0
- package/src/debug.ts +19 -9
- package/src/errors.ts +108 -2
- package/src/handle.ts +55 -29
- package/src/handles/MetaTags.tsx +73 -20
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +1 -0
- package/src/handles/meta.ts +30 -13
- package/src/host/cookie-handler.ts +21 -15
- package/src/host/errors.ts +8 -8
- package/src/host/index.ts +4 -7
- package/src/host/pattern-matcher.ts +27 -27
- package/src/host/router.ts +61 -39
- package/src/host/testing.ts +8 -8
- package/src/host/types.ts +15 -7
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +119 -29
- package/src/index.rsc.ts +155 -19
- package/src/index.ts +223 -30
- package/src/internal-debug.ts +11 -0
- package/src/loader.rsc.ts +26 -157
- package/src/loader.ts +27 -10
- package/src/network-error-thrower.tsx +3 -1
- package/src/outlet-provider.tsx +45 -0
- package/src/prerender/param-hash.ts +37 -0
- package/src/prerender/store.ts +186 -0
- package/src/prerender.ts +524 -0
- package/src/reverse.ts +351 -0
- package/src/root-error-boundary.tsx +41 -29
- package/src/route-content-wrapper.tsx +7 -4
- package/src/route-definition/dsl-helpers.ts +982 -0
- package/src/route-definition/helper-factories.ts +200 -0
- package/src/route-definition/helpers-types.ts +434 -0
- package/src/route-definition/index.ts +55 -0
- package/src/route-definition/redirect.ts +101 -0
- package/src/route-definition/resolve-handler-use.ts +149 -0
- package/src/route-definition.ts +1 -1428
- package/src/route-map-builder.ts +217 -123
- package/src/route-name.ts +53 -0
- package/src/route-types.ts +70 -8
- package/src/router/content-negotiation.ts +215 -0
- package/src/router/debug-manifest.ts +72 -0
- package/src/router/error-handling.ts +9 -9
- package/src/router/find-match.ts +160 -0
- package/src/router/handler-context.ts +435 -86
- package/src/router/intercept-resolution.ts +402 -0
- package/src/router/lazy-includes.ts +237 -0
- package/src/router/loader-resolution.ts +356 -128
- package/src/router/logging.ts +251 -0
- package/src/router/manifest.ts +154 -35
- package/src/router/match-api.ts +555 -0
- package/src/router/match-context.ts +5 -3
- package/src/router/match-handlers.ts +440 -0
- package/src/router/match-middleware/background-revalidation.ts +108 -93
- package/src/router/match-middleware/cache-lookup.ts +459 -10
- package/src/router/match-middleware/cache-store.ts +98 -26
- package/src/router/match-middleware/intercept-resolution.ts +57 -17
- package/src/router/match-middleware/segment-resolution.ts +80 -6
- package/src/router/match-pipelines.ts +10 -45
- package/src/router/match-result.ts +55 -33
- package/src/router/metrics.ts +240 -15
- package/src/router/middleware-cookies.ts +55 -0
- package/src/router/middleware-types.ts +220 -0
- package/src/router/middleware.ts +324 -369
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +211 -43
- package/src/router/prerender-match.ts +502 -0
- package/src/router/preview-match.ts +98 -0
- package/src/router/request-classification.ts +310 -0
- package/src/router/revalidation.ts +137 -38
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +41 -21
- package/src/router/router-interfaces.ts +484 -0
- package/src/router/router-options.ts +618 -0
- package/src/router/router-registry.ts +24 -0
- package/src/router/segment-resolution/fresh.ts +743 -0
- package/src/router/segment-resolution/helpers.ts +268 -0
- package/src/router/segment-resolution/loader-cache.ts +199 -0
- package/src/router/segment-resolution/revalidation.ts +1373 -0
- package/src/router/segment-resolution/static-store.ts +67 -0
- package/src/router/segment-resolution.ts +21 -0
- package/src/router/segment-wrappers.ts +291 -0
- package/src/router/telemetry-otel.ts +299 -0
- package/src/router/telemetry.ts +300 -0
- package/src/router/timeout.ts +148 -0
- package/src/router/trie-matching.ts +239 -0
- package/src/router/types.ts +78 -3
- package/src/router.ts +740 -4252
- package/src/rsc/handler-context.ts +45 -0
- package/src/rsc/handler.ts +907 -797
- package/src/rsc/helpers.ts +140 -6
- package/src/rsc/index.ts +0 -20
- package/src/rsc/loader-fetch.ts +229 -0
- package/src/rsc/manifest-init.ts +90 -0
- package/src/rsc/nonce.ts +14 -0
- package/src/rsc/origin-guard.ts +141 -0
- package/src/rsc/progressive-enhancement.ts +391 -0
- package/src/rsc/response-error.ts +37 -0
- package/src/rsc/response-route-handler.ts +347 -0
- package/src/rsc/rsc-rendering.ts +246 -0
- package/src/rsc/runtime-warnings.ts +42 -0
- package/src/rsc/server-action.ts +356 -0
- package/src/rsc/ssr-setup.ts +128 -0
- package/src/rsc/types.ts +46 -11
- package/src/search-params.ts +230 -0
- package/src/segment-system.tsx +165 -17
- package/src/server/context.ts +315 -58
- package/src/server/cookie-store.ts +190 -0
- package/src/server/fetchable-loader-store.ts +37 -0
- package/src/server/handle-store.ts +113 -15
- package/src/server/loader-registry.ts +24 -64
- package/src/server/request-context.ts +607 -81
- package/src/server.ts +35 -130
- package/src/ssr/index.tsx +103 -30
- package/src/static-handler.ts +126 -0
- package/src/theme/ThemeProvider.tsx +21 -15
- package/src/theme/ThemeScript.tsx +5 -5
- package/src/theme/constants.ts +5 -2
- package/src/theme/index.ts +4 -14
- package/src/theme/theme-context.ts +4 -30
- package/src/theme/theme-script.ts +21 -18
- package/src/types/boundaries.ts +158 -0
- package/src/types/cache-types.ts +198 -0
- package/src/types/error-types.ts +192 -0
- package/src/types/global-namespace.ts +100 -0
- package/src/types/handler-context.ts +791 -0
- package/src/types/index.ts +88 -0
- package/src/types/loader-types.ts +210 -0
- package/src/types/route-config.ts +170 -0
- package/src/types/route-entry.ts +109 -0
- package/src/types/segments.ts +150 -0
- package/src/types.ts +1 -1623
- package/src/urls/include-helper.ts +197 -0
- package/src/urls/index.ts +53 -0
- package/src/urls/path-helper-types.ts +346 -0
- package/src/urls/path-helper.ts +364 -0
- package/src/urls/pattern-types.ts +107 -0
- package/src/urls/response-types.ts +116 -0
- package/src/urls/type-extraction.ts +372 -0
- package/src/urls/urls-function.ts +98 -0
- package/src/urls.ts +1 -802
- package/src/use-loader.tsx +161 -81
- package/src/vite/discovery/bundle-postprocess.ts +181 -0
- package/src/vite/discovery/discover-routers.ts +348 -0
- package/src/vite/discovery/prerender-collection.ts +439 -0
- package/src/vite/discovery/route-types-writer.ts +258 -0
- package/src/vite/discovery/self-gen-tracking.ts +47 -0
- package/src/vite/discovery/state.ts +117 -0
- package/src/vite/discovery/virtual-module-codegen.ts +203 -0
- package/src/vite/index.ts +15 -1129
- package/src/vite/plugin-types.ts +103 -0
- package/src/vite/plugins/cjs-to-esm.ts +93 -0
- package/src/vite/plugins/client-ref-dedup.ts +115 -0
- package/src/vite/plugins/client-ref-hashing.ts +105 -0
- package/src/vite/{expose-action-id.ts → plugins/expose-action-id.ts} +72 -53
- package/src/vite/plugins/expose-id-utils.ts +299 -0
- package/src/vite/plugins/expose-ids/export-analysis.ts +296 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +209 -0
- package/src/vite/plugins/expose-ids/loader-transform.ts +74 -0
- package/src/vite/plugins/expose-ids/router-transform.ts +110 -0
- package/src/vite/plugins/expose-ids/types.ts +45 -0
- package/src/vite/plugins/expose-internal-ids.ts +786 -0
- package/src/vite/plugins/performance-tracks.ts +88 -0
- package/src/vite/plugins/refresh-cmd.ts +127 -0
- package/src/vite/plugins/use-cache-transform.ts +323 -0
- package/src/vite/plugins/version-injector.ts +83 -0
- package/src/vite/plugins/version-plugin.ts +266 -0
- package/src/vite/{virtual-entries.ts → plugins/virtual-entries.ts} +23 -14
- package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
- package/src/vite/rango.ts +462 -0
- package/src/vite/router-discovery.ts +918 -0
- package/src/vite/utils/ast-handler-extract.ts +517 -0
- package/src/vite/utils/banner.ts +36 -0
- package/src/vite/utils/bundle-analysis.ts +137 -0
- package/src/vite/utils/manifest-utils.ts +70 -0
- package/src/vite/{package-resolution.ts → utils/package-resolution.ts} +25 -29
- package/src/vite/utils/prerender-utils.ts +207 -0
- package/src/vite/utils/shared-utils.ts +170 -0
- package/CLAUDE.md +0 -43
- package/src/browser/lru-cache.ts +0 -69
- package/src/browser/request-controller.ts +0 -164
- package/src/cache/memory-store.ts +0 -253
- package/src/href-context.ts +0 -33
- package/src/href.ts +0 -255
- package/src/server/route-manifest-cache.ts +0 -173
- package/src/vite/expose-handle-id.ts +0 -209
- package/src/vite/expose-loader-id.ts +0 -426
- package/src/vite/expose-location-state-id.ts +0 -177
- /package/src/vite/{version.d.ts → plugins/version.d.ts} +0 -0
|
@@ -2,20 +2,34 @@ import type {
|
|
|
2
2
|
ServerActionBridge,
|
|
3
3
|
ServerActionBridgeConfig,
|
|
4
4
|
RscPayload,
|
|
5
|
-
ResolvedSegment,
|
|
6
|
-
NavigationStore,
|
|
7
5
|
} from "./types.js";
|
|
8
6
|
import { createPartialUpdater } from "./partial-update.js";
|
|
9
|
-
import { createNavigationTransaction } from "./navigation-
|
|
7
|
+
import { createNavigationTransaction } from "./navigation-transaction.js";
|
|
10
8
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "./
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
reconcileSegments,
|
|
10
|
+
reconcileErrorSegments,
|
|
11
|
+
} from "./segment-reconciler.js";
|
|
12
|
+
import { startTransition } from "react";
|
|
13
|
+
import type { EventController } from "./event-controller.js";
|
|
14
|
+
import {
|
|
15
|
+
toNetworkError,
|
|
16
|
+
emitNetworkError,
|
|
17
|
+
isBackgroundSuppressible,
|
|
18
|
+
} from "./network-error-handler.js";
|
|
19
|
+
import {
|
|
20
|
+
browserDebugLog,
|
|
21
|
+
isBrowserDebugEnabled,
|
|
22
|
+
startBrowserTransaction,
|
|
23
|
+
} from "./logging.js";
|
|
24
|
+
import { validateRedirectOrigin } from "./validate-redirect-origin.js";
|
|
25
|
+
import {
|
|
26
|
+
extractRscHeaderUrl,
|
|
27
|
+
emptyResponse,
|
|
28
|
+
teeWithCompletion,
|
|
29
|
+
} from "./response-adapter.js";
|
|
30
|
+
import { mergeLocationState } from "./history-state.js";
|
|
31
|
+
import { classifyActionOutcome } from "./action-coordinator.js";
|
|
32
|
+
import { getAppVersion } from "./app-version.js";
|
|
19
33
|
|
|
20
34
|
// Polyfill Symbol.dispose/asyncDispose for Safari and older browsers
|
|
21
35
|
if (typeof Symbol.dispose === "undefined") {
|
|
@@ -25,26 +39,16 @@ if (typeof Symbol.asyncDispose === "undefined") {
|
|
|
25
39
|
(Symbol as any).asyncDispose = Symbol("Symbol.asyncDispose");
|
|
26
40
|
}
|
|
27
41
|
|
|
28
|
-
/**
|
|
29
|
-
* Normalize action ID - returns the ID as-is
|
|
30
|
-
*
|
|
31
|
-
* Server actions have IDs like "hash#actionName" or "src/actions.ts#actionName".
|
|
32
|
-
* The full ID is used for tracking in the event controller. When subscribing
|
|
33
|
-
* via useAction, both exact matching (full ID) and suffix matching (action name
|
|
34
|
-
* only) are supported by the event controller.
|
|
35
|
-
*/
|
|
36
|
-
function normalizeActionId(actionId: string): string {
|
|
37
|
-
return actionId;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
42
|
/**
|
|
41
43
|
* Extended configuration for server action bridge with event controller
|
|
42
44
|
*/
|
|
43
|
-
export interface ServerActionBridgeConfigWithController
|
|
44
|
-
extends ServerActionBridgeConfig {
|
|
45
|
+
export interface ServerActionBridgeConfigWithController extends ServerActionBridgeConfig {
|
|
45
46
|
eventController: EventController;
|
|
46
|
-
/**
|
|
47
|
-
|
|
47
|
+
/** Callback to trigger SPA navigation (for action redirects) */
|
|
48
|
+
onNavigate?: (
|
|
49
|
+
url: string,
|
|
50
|
+
options?: { state?: unknown; replace?: boolean; _skipCache?: boolean },
|
|
51
|
+
) => Promise<void>;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
@@ -61,10 +65,17 @@ export interface ServerActionBridgeConfigWithController
|
|
|
61
65
|
* @returns ServerActionBridge instance
|
|
62
66
|
*/
|
|
63
67
|
export function createServerActionBridge(
|
|
64
|
-
config: ServerActionBridgeConfigWithController
|
|
68
|
+
config: ServerActionBridgeConfigWithController,
|
|
65
69
|
): ServerActionBridge {
|
|
66
|
-
const {
|
|
67
|
-
|
|
70
|
+
const {
|
|
71
|
+
store,
|
|
72
|
+
client,
|
|
73
|
+
eventController,
|
|
74
|
+
deps,
|
|
75
|
+
onUpdate,
|
|
76
|
+
renderSegments,
|
|
77
|
+
onNavigate,
|
|
78
|
+
} = config;
|
|
68
79
|
|
|
69
80
|
let isRegistered = false;
|
|
70
81
|
|
|
@@ -73,283 +84,392 @@ export function createServerActionBridge(
|
|
|
73
84
|
client,
|
|
74
85
|
onUpdate,
|
|
75
86
|
renderSegments,
|
|
76
|
-
|
|
87
|
+
getVersion: getAppVersion,
|
|
77
88
|
});
|
|
78
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Refetch current route via a navigation transaction.
|
|
92
|
+
* Encapsulates the repeated pattern of creating a navTx + fetchPartialUpdate
|
|
93
|
+
* used by navigated-away, hmr-missing, and consolidation-needed scenarios.
|
|
94
|
+
*/
|
|
95
|
+
async function refetchRoute(opts?: {
|
|
96
|
+
segments?: string[];
|
|
97
|
+
interceptSourceUrl?: string | null;
|
|
98
|
+
}): Promise<void> {
|
|
99
|
+
const src = opts?.interceptSourceUrl ?? null;
|
|
100
|
+
const navTx = createNavigationTransaction(
|
|
101
|
+
store,
|
|
102
|
+
eventController,
|
|
103
|
+
window.location.href,
|
|
104
|
+
{ replace: true, skipLoadingState: true },
|
|
105
|
+
);
|
|
106
|
+
try {
|
|
107
|
+
await fetchPartialUpdate(
|
|
108
|
+
window.location.href,
|
|
109
|
+
opts?.segments ?? [],
|
|
110
|
+
false,
|
|
111
|
+
navTx.handle.signal,
|
|
112
|
+
navTx.with({
|
|
113
|
+
url: window.location.href,
|
|
114
|
+
storeOnly: true,
|
|
115
|
+
...(src ? { intercept: true, interceptSourceUrl: src } : {}),
|
|
116
|
+
}),
|
|
117
|
+
{
|
|
118
|
+
type: "action" as const,
|
|
119
|
+
...(src ? { interceptSourceUrl: src } : {}),
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
} finally {
|
|
123
|
+
navTx[Symbol.dispose]();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
79
127
|
/**
|
|
80
128
|
* Server action callback handler
|
|
81
129
|
*/
|
|
82
130
|
async function handleServerAction(id: string, args: any[]): Promise<unknown> {
|
|
83
|
-
|
|
131
|
+
const tx = isBrowserDebugEnabled()
|
|
132
|
+
? startBrowserTransaction("action")
|
|
133
|
+
: null;
|
|
134
|
+
const log = (msg: string, details?: Record<string, unknown>) => {
|
|
135
|
+
if (tx) browserDebugLog(tx, msg, details);
|
|
136
|
+
};
|
|
137
|
+
|
|
84
138
|
const locationKey = window.history.state?.key;
|
|
85
|
-
|
|
86
|
-
console.log("ID", { id, actionId, args });
|
|
139
|
+
log("action start", { id, argsCount: args.length });
|
|
87
140
|
|
|
88
141
|
// Start action in event controller - handles lifecycle tracking
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.log(`[Browser] Args:`, args);
|
|
93
|
-
|
|
94
|
-
// Mark cache as stale immediately when action starts
|
|
95
|
-
// This ensures SWR pattern kicks in if user navigates away during action
|
|
96
|
-
store.markCacheAsStaleAndBroadcast();
|
|
97
|
-
|
|
98
|
-
// Create temporary references for serialization
|
|
99
|
-
const temporaryReferences = deps.createTemporaryReferenceSet();
|
|
100
|
-
|
|
101
|
-
// Capture URL pathname at action start to detect navigation during action
|
|
102
|
-
// Must use window.location (not store.path) because intercepts change URL
|
|
103
|
-
// without changing store.path (e.g., /kanban -> /kanban/card/1)
|
|
104
|
-
const actionStartPathname = window.location.pathname;
|
|
142
|
+
const handle = eventController.startAction(id, args);
|
|
143
|
+
try {
|
|
144
|
+
const segmentState = store.getSegmentState();
|
|
105
145
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
url.searchParams.set(
|
|
110
|
-
"_rsc_segments",
|
|
111
|
-
segmentState.currentSegmentIds.join(",")
|
|
112
|
-
);
|
|
113
|
-
// Add version param for version mismatch detection
|
|
114
|
-
if (version) {
|
|
115
|
-
url.searchParams.set("_rsc_v", version);
|
|
116
|
-
}
|
|
146
|
+
// Mark cache as stale immediately when action starts
|
|
147
|
+
// This ensures SWR pattern kicks in if user navigates away during action
|
|
148
|
+
store.markCacheAsStaleAndBroadcast();
|
|
117
149
|
|
|
118
|
-
|
|
119
|
-
|
|
150
|
+
// Create temporary references for serialization
|
|
151
|
+
const temporaryReferences = deps.createTemporaryReferenceSet();
|
|
120
152
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
);
|
|
126
|
-
console.log(`[Browser] Sending action request to: ${url.href}`);
|
|
127
|
-
console.log(
|
|
128
|
-
`[Browser] Current segments: ${segmentState.currentSegmentIds.join(", ")}`
|
|
129
|
-
);
|
|
153
|
+
// Capture URL pathname at action start to detect navigation during action
|
|
154
|
+
// Must use window.location (not store.path) because intercepts change URL
|
|
155
|
+
// without changing store.path (e.g., /kanban -> /kanban/card/1)
|
|
156
|
+
const actionStartPathname = window.location.pathname;
|
|
130
157
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// Send action request with stream tracking
|
|
144
|
-
const responsePromise = fetch(url, {
|
|
145
|
-
method: "POST",
|
|
146
|
-
headers: {
|
|
147
|
-
"rsc-action": id,
|
|
148
|
-
"X-RSC-Router-Client-Path": segmentState.currentUrl,
|
|
149
|
-
// Send intercept source URL so server can maintain intercept context
|
|
150
|
-
...(interceptSourceUrl && {
|
|
151
|
-
"X-RSC-Router-Intercept-Source": interceptSourceUrl,
|
|
152
|
-
}),
|
|
153
|
-
},
|
|
154
|
-
body: encodedBody,
|
|
155
|
-
}).then(async (response) => {
|
|
156
|
-
// Check for version mismatch - server wants us to reload
|
|
157
|
-
const reloadUrl = response.headers.get("X-RSC-Reload");
|
|
158
|
-
if (reloadUrl) {
|
|
159
|
-
console.log(`[Browser] Version mismatch on action - reloading: ${reloadUrl}`);
|
|
160
|
-
window.location.href = reloadUrl;
|
|
161
|
-
// Return a never-resolving promise to prevent further processing
|
|
162
|
-
return new Promise<Response>(() => {});
|
|
158
|
+
// Build action request URL with current segments
|
|
159
|
+
const url = new URL(window.location.href);
|
|
160
|
+
url.searchParams.set("_rsc_action", id);
|
|
161
|
+
url.searchParams.set(
|
|
162
|
+
"_rsc_segments",
|
|
163
|
+
segmentState.currentSegmentIds.join(","),
|
|
164
|
+
);
|
|
165
|
+
// Add version param for version mismatch detection
|
|
166
|
+
const version = getAppVersion();
|
|
167
|
+
if (version) {
|
|
168
|
+
url.searchParams.set("_rsc_v", version);
|
|
163
169
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
|
|
170
|
+
// Add router ID for app switch detection
|
|
171
|
+
const rid = store.getRouterId?.();
|
|
172
|
+
if (rid) {
|
|
173
|
+
url.searchParams.set("_rsc_rid", rid);
|
|
168
174
|
}
|
|
169
175
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
streamingToken?.end();
|
|
173
|
-
resolveStreamComplete();
|
|
174
|
-
return response;
|
|
175
|
-
}
|
|
176
|
+
// Encode arguments
|
|
177
|
+
const encodedBody = await deps.encodeReply(args, { temporaryReferences });
|
|
176
178
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
log("sending action request", {
|
|
180
|
+
url: url.href,
|
|
181
|
+
bodyType: typeof encodedBody,
|
|
182
|
+
isFormData: encodedBody instanceof FormData,
|
|
183
|
+
segmentCount: segmentState.currentSegmentIds.length,
|
|
184
|
+
});
|
|
179
185
|
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
// Track when the stream completes
|
|
187
|
+
let resolveStreamComplete: () => void;
|
|
188
|
+
const streamComplete = new Promise<void>((resolve) => {
|
|
189
|
+
resolveStreamComplete = resolve;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Get intercept source URL if in intercept context
|
|
193
|
+
const interceptSourceUrl = store.getInterceptSourceUrl();
|
|
194
|
+
|
|
195
|
+
// Track streaming token - will be set when response arrives
|
|
196
|
+
let streamingToken: { end(): void } | null = null;
|
|
197
|
+
|
|
198
|
+
// Use a dedicated abort controller for the fetch so we can cancel network
|
|
199
|
+
// I/O without disrupting the Flight stream once the response has arrived.
|
|
200
|
+
// Aborting a response mid-stream causes React's Flight decoder to throw
|
|
201
|
+
// asynchronous unhandled errors (BodyStreamBuffer was aborted).
|
|
202
|
+
const fetchAbort = new AbortController();
|
|
203
|
+
const onHandleAbort = () => fetchAbort.abort();
|
|
204
|
+
handle.signal.addEventListener("abort", onHandleAbort, { once: true });
|
|
205
|
+
|
|
206
|
+
// Send action request with stream tracking
|
|
207
|
+
const responsePromise = fetch(url, {
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: {
|
|
210
|
+
"rsc-action": id,
|
|
211
|
+
"X-RSC-Router-Client-Path": segmentState.currentUrl,
|
|
212
|
+
...(tx && { "X-RSC-Router-Request-Id": tx.requestId }),
|
|
213
|
+
...(interceptSourceUrl && {
|
|
214
|
+
"X-RSC-Router-Intercept-Source": interceptSourceUrl,
|
|
215
|
+
}),
|
|
216
|
+
},
|
|
217
|
+
body: encodedBody,
|
|
218
|
+
signal: fetchAbort.signal,
|
|
219
|
+
}).then(async (response) => {
|
|
220
|
+
// Response arrived — disconnect fetch abort from handle abort so
|
|
221
|
+
// abortAllActions() doesn't disrupt the in-progress Flight stream.
|
|
222
|
+
handle.signal.removeEventListener("abort", onHandleAbort);
|
|
223
|
+
|
|
224
|
+
// Check for version mismatch - server wants us to reload
|
|
225
|
+
const reload = extractRscHeaderUrl(response, "X-RSC-Reload");
|
|
226
|
+
if (reload === "blocked") {
|
|
227
|
+
resolveStreamComplete();
|
|
228
|
+
return emptyResponse();
|
|
229
|
+
}
|
|
230
|
+
if (reload) {
|
|
231
|
+
log("version mismatch on action, reloading", {
|
|
232
|
+
reloadUrl: reload.url,
|
|
233
|
+
});
|
|
234
|
+
window.location.href = reload.url;
|
|
235
|
+
return new Promise<Response>(() => {});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Simple redirect from action (no state, no RSC payload).
|
|
239
|
+
// Short-circuits before createFromFetch — no Flight deserialization needed.
|
|
240
|
+
// Check handle.signal.aborted to avoid redirecting from a stale action
|
|
241
|
+
// when the user has already navigated away.
|
|
242
|
+
const redirect = extractRscHeaderUrl(response, "X-RSC-Redirect");
|
|
243
|
+
if (redirect && redirect !== "blocked" && !handle.signal.aborted) {
|
|
244
|
+
log("action simple redirect", { url: redirect.url });
|
|
245
|
+
handle.complete(undefined);
|
|
246
|
+
if (onNavigate) {
|
|
247
|
+
await onNavigate(redirect.url, {
|
|
248
|
+
replace: true,
|
|
249
|
+
_skipCache: true,
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
window.location.href = redirect.url;
|
|
187
253
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
streamingToken?.end();
|
|
254
|
+
return new Promise<Response>(() => {});
|
|
255
|
+
}
|
|
256
|
+
if (redirect === "blocked") {
|
|
192
257
|
resolveStreamComplete();
|
|
258
|
+
return emptyResponse();
|
|
193
259
|
}
|
|
194
|
-
})().catch((error) => {
|
|
195
|
-
console.error("[STREAMING] Error reading tracking stream:", error);
|
|
196
|
-
streamingToken?.end();
|
|
197
|
-
});
|
|
198
260
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
statusText: response.statusText,
|
|
204
|
-
});
|
|
205
|
-
});
|
|
261
|
+
// Start streaming immediately when response arrives
|
|
262
|
+
if (!handle.signal.aborted) {
|
|
263
|
+
streamingToken = handle.startStreaming();
|
|
264
|
+
}
|
|
206
265
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
266
|
+
return teeWithCompletion(response, () => {
|
|
267
|
+
log("stream complete");
|
|
268
|
+
streamingToken?.end();
|
|
269
|
+
resolveStreamComplete();
|
|
270
|
+
});
|
|
212
271
|
});
|
|
213
|
-
} catch (error) {
|
|
214
|
-
// Clean up streaming token on error (may be null if fetch failed before .then() ran)
|
|
215
|
-
// The token is assigned in .then() callback which runs before this catch block,
|
|
216
|
-
// but TypeScript doesn't track cross-async assignments, so use type assertion
|
|
217
|
-
(streamingToken as { end(): void } | null)?.end();
|
|
218
|
-
// resolveStreamComplete is assigned in the Promise constructor so it's safe to call
|
|
219
|
-
resolveStreamComplete!();
|
|
220
|
-
|
|
221
|
-
// Convert network-level errors to NetworkError for proper handling
|
|
222
|
-
if (isNetworkError(error)) {
|
|
223
|
-
const networkError = new NetworkError(
|
|
224
|
-
"Unable to connect to server. Please check your connection.",
|
|
225
|
-
{
|
|
226
|
-
cause: error,
|
|
227
|
-
url: url.toString(),
|
|
228
|
-
operation: "action",
|
|
229
|
-
}
|
|
230
|
-
);
|
|
231
272
|
|
|
232
|
-
|
|
233
|
-
|
|
273
|
+
// Deserialize response (MUST use same temporaryReferences)
|
|
274
|
+
let payload: RscPayload;
|
|
275
|
+
try {
|
|
276
|
+
payload = await deps.createFromFetch<RscPayload>(responsePromise, {
|
|
277
|
+
temporaryReferences,
|
|
278
|
+
});
|
|
279
|
+
} catch (error) {
|
|
280
|
+
// Clean up streaming token on error (may be null if fetch failed before .then() ran)
|
|
281
|
+
// The token is assigned in .then() callback which runs before this catch block,
|
|
282
|
+
// but TypeScript doesn't track cross-async assignments, so use type assertion
|
|
283
|
+
(streamingToken as { end(): void } | null)?.end();
|
|
284
|
+
// resolveStreamComplete is assigned in the Promise constructor so it's safe to call
|
|
285
|
+
resolveStreamComplete!();
|
|
286
|
+
|
|
287
|
+
// Silently swallow abort errors — the action was intentionally cancelled
|
|
288
|
+
// (e.g., user navigated away or abortAllActions was called).
|
|
289
|
+
// Return undefined instead of throwing to avoid surfacing as a page error.
|
|
290
|
+
// Check both DOMException AbortError and stream-level abort messages
|
|
291
|
+
// (BodyStreamBuffer was aborted) that propagate from the aborted fetch.
|
|
292
|
+
if (handle.signal.aborted) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
234
295
|
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
root: createElement(NetworkErrorThrower, { error: networkError }),
|
|
240
|
-
metadata: {
|
|
241
|
-
pathname: segmentState.currentUrl,
|
|
242
|
-
segments: [],
|
|
243
|
-
isError: true,
|
|
244
|
-
},
|
|
245
|
-
});
|
|
296
|
+
// Convert network-level errors to NetworkError for proper handling
|
|
297
|
+
const networkError = toNetworkError(error, {
|
|
298
|
+
url: url.toString(),
|
|
299
|
+
operation: "action",
|
|
246
300
|
});
|
|
301
|
+
if (networkError) {
|
|
302
|
+
handle.fail(networkError);
|
|
303
|
+
emitNetworkError(onUpdate, networkError, segmentState.currentUrl);
|
|
304
|
+
throw networkError;
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
247
308
|
|
|
248
|
-
|
|
309
|
+
log("action response received", {
|
|
310
|
+
isPartial: payload.metadata?.isPartial,
|
|
311
|
+
isError: payload.metadata?.isError,
|
|
312
|
+
matchedCount: payload.metadata?.matched?.length ?? 0,
|
|
313
|
+
diffCount: payload.metadata?.diff?.length ?? 0,
|
|
314
|
+
});
|
|
315
|
+
// Guard: if the action was aborted while streaming (e.g., user navigated
|
|
316
|
+
// away or abortAllActions fired), bail out before any reconcile/render/cache
|
|
317
|
+
// writes to avoid overwriting the current UI with stale action results.
|
|
318
|
+
if (handle.signal.aborted) {
|
|
319
|
+
log("action aborted after response, skipping reconciliation");
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Process response
|
|
324
|
+
const { metadata, returnValue } = payload;
|
|
325
|
+
|
|
326
|
+
// Handle action redirect: server converted the redirect to a Flight payload
|
|
327
|
+
// so we can perform SPA navigation instead of a full page reload.
|
|
328
|
+
// Check handle.signal.aborted to avoid redirecting from a stale action
|
|
329
|
+
// when the user has already navigated away.
|
|
330
|
+
if (metadata?.redirect && !handle.signal.aborted) {
|
|
331
|
+
const redirectUrl = validateRedirectOrigin(
|
|
332
|
+
metadata.redirect.url,
|
|
333
|
+
window.location.origin,
|
|
334
|
+
);
|
|
335
|
+
if (!redirectUrl) {
|
|
336
|
+
log("blocked action redirect payload", {
|
|
337
|
+
url: metadata.redirect.url,
|
|
338
|
+
});
|
|
339
|
+
handle.complete(returnValue?.data);
|
|
340
|
+
return returnValue?.data;
|
|
341
|
+
}
|
|
342
|
+
const redirectState = metadata.locationState;
|
|
343
|
+
log("action redirect", { url: redirectUrl });
|
|
344
|
+
handle.complete(returnValue?.data);
|
|
345
|
+
if (onNavigate) {
|
|
346
|
+
await onNavigate(redirectUrl, {
|
|
347
|
+
state: redirectState,
|
|
348
|
+
replace: true,
|
|
349
|
+
_skipCache: true,
|
|
350
|
+
});
|
|
351
|
+
} else {
|
|
352
|
+
window.location.href = redirectUrl;
|
|
353
|
+
}
|
|
354
|
+
return returnValue?.data;
|
|
249
355
|
}
|
|
250
|
-
throw error;
|
|
251
|
-
}
|
|
252
356
|
|
|
253
|
-
|
|
357
|
+
// Bail out if the action was aborted after deserialization (e.g. user
|
|
358
|
+
// navigated away or abortAllActions was called while the Flight stream
|
|
359
|
+
// was being consumed). Without this check the code below would mutate
|
|
360
|
+
// the store / UI for a stale action.
|
|
361
|
+
if (handle.signal.aborted) {
|
|
362
|
+
log("action aborted after deserialization, skipping mutations");
|
|
363
|
+
return returnValue?.data;
|
|
364
|
+
}
|
|
254
365
|
|
|
255
|
-
|
|
256
|
-
const { metadata, returnValue } = payload;
|
|
257
|
-
const { matched, diff, segments, isPartial, isError } = metadata || {};
|
|
366
|
+
const { matched, diff, segments, isPartial, isError } = metadata || {};
|
|
258
367
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
console.log(`[Browser] Action result:`, returnValue);
|
|
262
|
-
if (!returnValue.ok) {
|
|
368
|
+
// Log action result
|
|
369
|
+
if (returnValue && !returnValue.ok) {
|
|
263
370
|
console.error(`[Browser] Action failed:`, returnValue.data);
|
|
264
371
|
}
|
|
265
|
-
}
|
|
266
372
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
373
|
+
// Handle error responses with error boundary UI
|
|
374
|
+
if (isError && isPartial && segments && diff) {
|
|
375
|
+
log("processing error boundary response");
|
|
270
376
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
377
|
+
// Fail current handle BEFORE aborting all actions so the event controller
|
|
378
|
+
// records the error state (abortAllActions clears inflight entries)
|
|
379
|
+
if (returnValue && !returnValue.ok) {
|
|
380
|
+
handle.fail(returnValue.data);
|
|
381
|
+
}
|
|
274
382
|
|
|
275
|
-
|
|
276
|
-
|
|
383
|
+
// Abort all other pending action requests - error takes precedence
|
|
384
|
+
// This prevents other actions from completing and overwriting the error UI
|
|
385
|
+
eventController.abortAllActions();
|
|
277
386
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const cached = store.getCachedSegments(currentKey);
|
|
281
|
-
const cachedSegments = cached?.segments || [];
|
|
387
|
+
// Clear concurrent action tracking - no consolidation needed when showing error
|
|
388
|
+
handle.clearConsolidation();
|
|
282
389
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
390
|
+
// Get current page's cached segments
|
|
391
|
+
const currentKey = store.getHistoryKey();
|
|
392
|
+
const cached = store.getCachedSegments(currentKey);
|
|
393
|
+
const cachedSegments = cached?.segments || [];
|
|
394
|
+
|
|
395
|
+
// Reconcile error segments with cached tree
|
|
396
|
+
const errorResult = reconcileErrorSegments(cachedSegments, segments);
|
|
397
|
+
|
|
398
|
+
// Render the full tree with error segment merged with parent layouts
|
|
399
|
+
const errorTree = await renderSegments(errorResult.mainSegments, {
|
|
400
|
+
isAction: true,
|
|
401
|
+
interceptSegments:
|
|
402
|
+
errorResult.interceptSegments.length > 0
|
|
403
|
+
? errorResult.interceptSegments
|
|
404
|
+
: undefined,
|
|
405
|
+
});
|
|
295
406
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
});
|
|
407
|
+
// Re-check route stability after async renderSegments — user may have
|
|
408
|
+
// navigated away while the error tree was being prepared.
|
|
409
|
+
if (window.location.pathname !== actionStartPathname) {
|
|
410
|
+
log("user navigated during error render, skipping");
|
|
411
|
+
if (returnValue && !returnValue.ok) {
|
|
412
|
+
throw returnValue.data;
|
|
413
|
+
}
|
|
414
|
+
handle.complete(undefined);
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
const currentKeyNow = store.getHistoryKey();
|
|
418
|
+
if (currentKeyNow !== currentKey) {
|
|
419
|
+
log("history key changed during error render, skipping cache update");
|
|
420
|
+
if (returnValue && !returnValue.ok) {
|
|
421
|
+
throw returnValue.data;
|
|
422
|
+
}
|
|
423
|
+
handle.complete(undefined);
|
|
424
|
+
return undefined;
|
|
425
|
+
}
|
|
316
426
|
|
|
317
|
-
|
|
427
|
+
// Update UI with error boundary
|
|
428
|
+
startTransition(() => {
|
|
429
|
+
onUpdate({ root: errorTree, metadata: metadata! });
|
|
430
|
+
});
|
|
318
431
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
432
|
+
// Update segment tracking to exclude error segment IDs
|
|
433
|
+
const errorSegmentIds = new Set(diff);
|
|
434
|
+
const segmentIdsAfterError = segmentState.currentSegmentIds.filter(
|
|
435
|
+
(id) => !errorSegmentIds.has(id),
|
|
436
|
+
);
|
|
324
437
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
438
|
+
// Update store state
|
|
439
|
+
store.setSegmentIds(segmentIdsAfterError);
|
|
440
|
+
const currentHandleData = eventController.getHandleState().data;
|
|
441
|
+
store.cacheSegmentsForHistory(
|
|
442
|
+
currentKey,
|
|
443
|
+
errorResult.segments,
|
|
444
|
+
currentHandleData,
|
|
445
|
+
);
|
|
329
446
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
447
|
+
// Throw the error so the action promise rejects
|
|
448
|
+
if (returnValue && !returnValue.ok) {
|
|
449
|
+
throw returnValue.data;
|
|
450
|
+
}
|
|
334
451
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
throw returnValue.data;
|
|
452
|
+
// No error in returnValue (shouldn't happen with isError: true)
|
|
453
|
+
handle.complete(undefined);
|
|
454
|
+
return undefined;
|
|
339
455
|
}
|
|
340
456
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
457
|
+
if (!isPartial) {
|
|
458
|
+
// Protocol invariant: action revalidation responses MUST be partial.
|
|
459
|
+
// The server always sends isPartial: true for successful revalidation
|
|
460
|
+
// and isPartial: true + isError: true for error boundary responses.
|
|
461
|
+
// A non-partial payload here indicates a server-side bug.
|
|
462
|
+
throw new Error(
|
|
463
|
+
`[Browser] Action response missing isPartial — the server must ` +
|
|
464
|
+
`always send partial payloads for action revalidation.`,
|
|
465
|
+
);
|
|
466
|
+
}
|
|
345
467
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
);
|
|
352
|
-
console.log(`[Browser] Server expects client to have:`, matched);
|
|
468
|
+
log("processing partial update", {
|
|
469
|
+
serverSegments: segments?.length ?? 0,
|
|
470
|
+
diff: diff?.join(", ") ?? "",
|
|
471
|
+
matched: matched?.join(", ") ?? "",
|
|
472
|
+
});
|
|
353
473
|
|
|
354
474
|
// Record revalidated segments for concurrent action tracking
|
|
355
475
|
if (diff) {
|
|
@@ -360,375 +480,174 @@ export function createServerActionBridge(
|
|
|
360
480
|
const currentKey = store.getHistoryKey();
|
|
361
481
|
const cached = store.getCachedSegments(currentKey);
|
|
362
482
|
const cachedSegments = cached?.segments || [];
|
|
363
|
-
const currentSegmentMap = new Map<string, ResolvedSegment>();
|
|
364
|
-
cachedSegments.forEach((s) => currentSegmentMap.set(s.id, s));
|
|
365
|
-
|
|
366
|
-
console.log(
|
|
367
|
-
`[Browser] Client cache has ${currentSegmentMap.size} entries:`,
|
|
368
|
-
Array.from(currentSegmentMap.keys())
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
// Create lookup for new segments from server
|
|
372
|
-
const newSegmentMap = new Map<string, ResolvedSegment>();
|
|
373
|
-
(segments || []).forEach((s: ResolvedSegment) =>
|
|
374
|
-
newSegmentMap.set(s.id, s)
|
|
375
|
-
);
|
|
376
483
|
|
|
377
484
|
if (!matched) {
|
|
378
|
-
console.log(`[Browser] Matched segments: ${matched}`);
|
|
379
485
|
throw new Error("No matched segments in response");
|
|
380
486
|
}
|
|
381
487
|
|
|
382
|
-
//
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return mergeSegmentLoaders(fromServer, fromCache);
|
|
392
|
-
}
|
|
393
|
-
// When server returns component: null for a layout segment, it means
|
|
394
|
-
// "this segment doesn't need re-rendering" - preserve the cached component
|
|
395
|
-
// to maintain the outlet chain and prevent React tree changes
|
|
396
|
-
const cached = currentSegmentMap.get(segId); // Re-fetch to avoid type narrowing issues
|
|
397
|
-
if (
|
|
398
|
-
fromServer.component === null &&
|
|
399
|
-
fromServer.type === "layout" &&
|
|
400
|
-
cached?.component != null
|
|
401
|
-
) {
|
|
402
|
-
console.log(
|
|
403
|
-
`[Browser] Preserving cached component for layout ${segId} (server returned null)`
|
|
404
|
-
);
|
|
405
|
-
return { ...fromServer, component: cached.component };
|
|
406
|
-
}
|
|
407
|
-
// Dev-mode assertion: warn if tree structure would change
|
|
408
|
-
if (cached) {
|
|
409
|
-
assertSegmentStructure(cached, fromServer, "action-bridge");
|
|
410
|
-
}
|
|
411
|
-
// Preserve cached loading value to maintain consistent tree structure.
|
|
412
|
-
// SSR may set loading=false for skipSSR routes, but actions set
|
|
413
|
-
// loading=<skeleton> (isSSR=false). Changing loading between renders
|
|
414
|
-
// alters the React tree (with/without RouteContentWrapper), causing
|
|
415
|
-
// remounts that destroy useActionState.
|
|
416
|
-
if (
|
|
417
|
-
cached &&
|
|
418
|
-
cached.loading !== undefined &&
|
|
419
|
-
fromServer.loading !== cached.loading
|
|
420
|
-
) {
|
|
421
|
-
return { ...fromServer, loading: cached.loading };
|
|
422
|
-
}
|
|
423
|
-
return fromServer;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// Fall back to current page's cached segments
|
|
427
|
-
if (!fromCache) {
|
|
428
|
-
console.error(`[Browser] MISSING SEGMENT: ${segId} not in cache!`);
|
|
429
|
-
}
|
|
430
|
-
return fromCache;
|
|
431
|
-
})
|
|
432
|
-
.filter(Boolean) as ResolvedSegment[];
|
|
433
|
-
|
|
434
|
-
console.log(
|
|
435
|
-
`[Browser] Rebuilt ${fullSegments.length} segments from matched array`
|
|
436
|
-
);
|
|
488
|
+
// Reconcile server segments with cached segments (single source of truth)
|
|
489
|
+
const reconciled = reconcileSegments({
|
|
490
|
+
actor: "action",
|
|
491
|
+
matched,
|
|
492
|
+
diff: diff || [],
|
|
493
|
+
serverSegments: segments || [],
|
|
494
|
+
cachedSegments,
|
|
495
|
+
});
|
|
496
|
+
const fullSegments = reconciled.segments;
|
|
437
497
|
|
|
438
498
|
const returnData = returnValue?.data;
|
|
439
499
|
|
|
440
|
-
console.log(
|
|
441
|
-
`[Browser] Action complete - UI updated (after action state committed)`
|
|
442
|
-
);
|
|
443
|
-
|
|
444
500
|
if (returnValue && !returnValue.ok) {
|
|
445
501
|
handle.fail(returnValue.data);
|
|
446
502
|
throw returnValue.data;
|
|
447
503
|
}
|
|
448
504
|
|
|
449
|
-
//
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
// Check if the history key changed (different cache entry)
|
|
464
|
-
// This happens when navigating between intercept and non-intercept routes
|
|
465
|
-
if (currentLocationKey !== locationKey) {
|
|
466
|
-
console.log(
|
|
467
|
-
`[Browser] History key changed (${locationKey} -> ${currentLocationKey}), triggering background revalidation`
|
|
468
|
-
);
|
|
505
|
+
// Classify the post-reconciliation scenario
|
|
506
|
+
const scenario = classifyActionOutcome({
|
|
507
|
+
handleId: handle.id,
|
|
508
|
+
inflightActions: eventController.getInflightActions(),
|
|
509
|
+
hadAnyConcurrentActions: eventController.hadAnyConcurrentActions(),
|
|
510
|
+
revalidatedSegments: handle.getRevalidatedSegments(),
|
|
511
|
+
actionStartPathname,
|
|
512
|
+
currentPathname: window.location.pathname,
|
|
513
|
+
actionStartLocationKey: locationKey,
|
|
514
|
+
currentLocationKey: window.history.state?.key,
|
|
515
|
+
reconciledSegmentCount: fullSegments.length,
|
|
516
|
+
matchedCount: matched.length,
|
|
517
|
+
currentInterceptSource: store.getInterceptSourceUrl(),
|
|
518
|
+
});
|
|
469
519
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
window.location.href,
|
|
493
|
-
{ replace: true, skipLoadingState: true }
|
|
494
|
-
);
|
|
495
|
-
fetchPartialUpdate(
|
|
496
|
-
window.location.href,
|
|
497
|
-
[],
|
|
498
|
-
false,
|
|
499
|
-
navTx.handle.signal,
|
|
500
|
-
navTx.with({
|
|
501
|
-
url: window.location.href,
|
|
502
|
-
storeOnly: true,
|
|
503
|
-
}),
|
|
504
|
-
{
|
|
505
|
-
isAction: true,
|
|
506
|
-
}
|
|
507
|
-
).then(() => {
|
|
508
|
-
console.log(`[Browser] Background revalidation complete`);
|
|
509
|
-
});
|
|
520
|
+
switch (scenario.type) {
|
|
521
|
+
case "navigated-away": {
|
|
522
|
+
log("user navigated away during action", {
|
|
523
|
+
from: actionStartPathname,
|
|
524
|
+
to: window.location.pathname,
|
|
525
|
+
historyKeyChanged: scenario.historyKeyChanged,
|
|
526
|
+
});
|
|
527
|
+
// Clear concurrent action tracking - don't consolidate for old route's segments
|
|
528
|
+
handle.clearConsolidation();
|
|
529
|
+
|
|
530
|
+
if (scenario.historyKeyChanged) {
|
|
531
|
+
if (!scenario.onInterceptRoute) {
|
|
532
|
+
store.markCacheAsStaleAndBroadcast();
|
|
533
|
+
refetchRoute().catch((error) => {
|
|
534
|
+
if (isBackgroundSuppressible(error)) return;
|
|
535
|
+
console.error(
|
|
536
|
+
"[Browser] Background revalidation failed:",
|
|
537
|
+
error,
|
|
538
|
+
);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
break;
|
|
510
542
|
}
|
|
511
543
|
|
|
512
|
-
|
|
513
|
-
|
|
544
|
+
// Same history key but different pathname - safe to refetch current route
|
|
545
|
+
store.markCacheAsStaleAndBroadcast();
|
|
546
|
+
await refetchRoute({
|
|
547
|
+
interceptSourceUrl: store.getInterceptSourceUrl(),
|
|
548
|
+
});
|
|
549
|
+
break;
|
|
514
550
|
}
|
|
515
551
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
store
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
{ replace: true, skipLoadingState: true }
|
|
525
|
-
);
|
|
526
|
-
// Preserve intercept context
|
|
527
|
-
const currentInterceptSource = store.getInterceptSourceUrl();
|
|
528
|
-
await fetchPartialUpdate(
|
|
529
|
-
window.location.href,
|
|
530
|
-
[], // Empty array = refetch all segments for current route
|
|
531
|
-
false,
|
|
532
|
-
navTx.handle.signal,
|
|
533
|
-
navTx.with({
|
|
534
|
-
url: window.location.href,
|
|
535
|
-
storeOnly: true,
|
|
536
|
-
intercept: !!currentInterceptSource,
|
|
537
|
-
interceptSourceUrl: currentInterceptSource ?? undefined,
|
|
538
|
-
}),
|
|
539
|
-
{
|
|
540
|
-
isAction: true,
|
|
541
|
-
interceptSourceUrl: currentInterceptSource ?? undefined,
|
|
542
|
-
}
|
|
543
|
-
);
|
|
544
|
-
console.log(`[Browser] Refetch after navigation complete`);
|
|
545
|
-
handle.complete(returnData);
|
|
546
|
-
return returnData;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// HMR resilience check - only runs if user DIDN'T navigate away
|
|
550
|
-
if (fullSegments.length < matched.length) {
|
|
551
|
-
console.warn(
|
|
552
|
-
`[Browser] Missing segments after action (HMR detected), refetching...`
|
|
553
|
-
);
|
|
554
|
-
|
|
555
|
-
using navTx = createNavigationTransaction(
|
|
556
|
-
store,
|
|
557
|
-
eventController,
|
|
558
|
-
window.location.href,
|
|
559
|
-
{ replace: true, skipLoadingState: true }
|
|
560
|
-
);
|
|
561
|
-
await fetchPartialUpdate(
|
|
562
|
-
window.location.href,
|
|
563
|
-
[],
|
|
564
|
-
false,
|
|
565
|
-
navTx.handle.signal,
|
|
566
|
-
navTx.with({
|
|
567
|
-
url: window.location.href,
|
|
568
|
-
storeOnly: true,
|
|
569
|
-
intercept: !!interceptSourceUrl,
|
|
570
|
-
interceptSourceUrl: interceptSourceUrl ?? undefined,
|
|
571
|
-
}),
|
|
572
|
-
{
|
|
573
|
-
isAction: true,
|
|
574
|
-
interceptSourceUrl: interceptSourceUrl ?? undefined,
|
|
575
|
-
}
|
|
576
|
-
);
|
|
577
|
-
console.log(
|
|
578
|
-
`[Browser] Refetch complete (HMR), now returning action result`
|
|
579
|
-
);
|
|
552
|
+
case "hmr-missing": {
|
|
553
|
+
console.warn(
|
|
554
|
+
`[Browser] Missing segments after action (HMR detected), refetching...`,
|
|
555
|
+
);
|
|
556
|
+
await refetchRoute({ interceptSourceUrl });
|
|
557
|
+
store.broadcastCacheInvalidation();
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
580
560
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
561
|
+
case "consolidation-needed": {
|
|
562
|
+
log("consolidation fetch needed", {
|
|
563
|
+
segmentIds: scenario.segmentIds,
|
|
564
|
+
});
|
|
565
|
+
// Calculate segments to send (exclude the ones we want fresh)
|
|
566
|
+
const currentSegmentIds = store.getSegmentState().currentSegmentIds;
|
|
567
|
+
const segmentsToSend = currentSegmentIds.filter(
|
|
568
|
+
(sid) => !scenario.segmentIds.includes(sid),
|
|
569
|
+
);
|
|
586
570
|
|
|
587
|
-
|
|
588
|
-
|
|
571
|
+
// Clear consolidation tracking before fetch
|
|
572
|
+
handle.clearConsolidation();
|
|
589
573
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const currentSegmentIds = store.getSegmentState().currentSegmentIds;
|
|
598
|
-
const segmentsToSend = currentSegmentIds.filter(
|
|
599
|
-
(id) => !consolidationSegments.includes(id)
|
|
600
|
-
);
|
|
574
|
+
await refetchRoute({
|
|
575
|
+
segments: segmentsToSend,
|
|
576
|
+
interceptSourceUrl,
|
|
577
|
+
});
|
|
578
|
+
store.broadcastCacheInvalidation();
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
601
581
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
582
|
+
case "concurrent-skip": {
|
|
583
|
+
log("skipping UI update, other actions fetching", {
|
|
584
|
+
otherCount: scenario.otherFetchingCount,
|
|
585
|
+
});
|
|
586
|
+
// Only update store if history key hasn't changed (user didn't navigate away)
|
|
587
|
+
const currentKeyNow = store.getHistoryKey();
|
|
588
|
+
if (currentKeyNow === currentKey) {
|
|
589
|
+
store.setSegmentIds(matched);
|
|
590
|
+
const currentHandleData = eventController.getHandleState().data;
|
|
591
|
+
store.cacheSegmentsForHistory(
|
|
592
|
+
currentKey,
|
|
593
|
+
fullSegments,
|
|
594
|
+
currentHandleData,
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
606
599
|
|
|
607
|
-
|
|
608
|
-
|
|
600
|
+
case "normal": {
|
|
601
|
+
// Prepare new tree (await loader data resolution)
|
|
602
|
+
const newTree = await renderSegments(reconciled.mainSegments, {
|
|
603
|
+
isAction: true,
|
|
604
|
+
interceptSegments:
|
|
605
|
+
reconciled.interceptSegments.length > 0
|
|
606
|
+
? reconciled.interceptSegments
|
|
607
|
+
: undefined,
|
|
608
|
+
});
|
|
609
609
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
);
|
|
610
|
+
// Re-check if user navigated away (could happen during async renderSegments)
|
|
611
|
+
if (window.location.pathname !== actionStartPathname) {
|
|
612
|
+
log("user navigated during render, skipping");
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
616
615
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
navTx.with({
|
|
624
|
-
url: window.location.href,
|
|
625
|
-
storeOnly: true,
|
|
626
|
-
intercept: !!interceptSourceUrl,
|
|
627
|
-
interceptSourceUrl: interceptSourceUrl ?? undefined,
|
|
628
|
-
}),
|
|
629
|
-
{
|
|
630
|
-
isAction: true,
|
|
631
|
-
interceptSourceUrl: interceptSourceUrl ?? undefined,
|
|
616
|
+
// Verify the store's current key still matches what we captured at action start
|
|
617
|
+
// If they differ, user navigated away and we should NOT cache under the old key
|
|
618
|
+
const currentKeyNow = store.getHistoryKey();
|
|
619
|
+
if (currentKeyNow !== currentKey) {
|
|
620
|
+
log("history key changed during action, skipping cache update");
|
|
621
|
+
break;
|
|
632
622
|
}
|
|
633
|
-
);
|
|
634
623
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
console.log(
|
|
639
|
-
`[Browser] Consolidate/Reconcile - Returning to React:`,
|
|
640
|
-
returnData
|
|
641
|
-
);
|
|
624
|
+
startTransition(() => {
|
|
625
|
+
onUpdate({ root: newTree, metadata: metadata! });
|
|
626
|
+
});
|
|
642
627
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
628
|
+
// Apply server-set location state to history.state (non-redirect flow)
|
|
629
|
+
const actionLocationState = metadata?.locationState;
|
|
630
|
+
if (actionLocationState) {
|
|
631
|
+
mergeLocationState(actionLocationState);
|
|
632
|
+
}
|
|
646
633
|
|
|
647
|
-
|
|
648
|
-
// Exclude the current action since we already have our response
|
|
649
|
-
// We don't need to wait for streaming to complete - just for the response to arrive
|
|
650
|
-
const otherFetchingActions = [...eventController.getInflightActions().values()].filter(
|
|
651
|
-
(a) => a.phase === "fetching" && a.id !== handle.id
|
|
652
|
-
);
|
|
653
|
-
if (otherFetchingActions.length > 0) {
|
|
654
|
-
console.log(
|
|
655
|
-
`[Browser] Skipping UI update - ${otherFetchingActions.length} other action(s) still fetching`
|
|
656
|
-
);
|
|
657
|
-
console.log(
|
|
658
|
-
`[Browser] Multi actions - Returning to React (no cache clear):`,
|
|
659
|
-
returnData
|
|
660
|
-
);
|
|
661
|
-
// Only update store if history key hasn't changed (user didn't navigate away)
|
|
662
|
-
const currentKeyNow = store.getHistoryKey();
|
|
663
|
-
if (currentKeyNow === currentKey) {
|
|
634
|
+
// Update store state
|
|
664
635
|
store.setSegmentIds(matched);
|
|
665
636
|
const currentHandleData = eventController.getHandleState().data;
|
|
666
|
-
store.cacheSegmentsForHistory(
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
637
|
+
store.cacheSegmentsForHistory(
|
|
638
|
+
currentKey,
|
|
639
|
+
fullSegments,
|
|
640
|
+
currentHandleData,
|
|
670
641
|
);
|
|
642
|
+
store.markCacheAsStaleAndBroadcast();
|
|
643
|
+
break;
|
|
671
644
|
}
|
|
672
|
-
handle.complete(returnData);
|
|
673
|
-
return returnData;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// No concurrent actions - normal flow with single action
|
|
677
|
-
// INTERCEPT HANDLING: Separate intercept segments for explicit injection
|
|
678
|
-
const isInterceptSegment = (s: ResolvedSegment) =>
|
|
679
|
-
s.namespace?.startsWith("intercept:") ||
|
|
680
|
-
(s.type === "parallel" && s.id.includes(".@"));
|
|
681
|
-
|
|
682
|
-
const interceptSegments = fullSegments.filter(isInterceptSegment);
|
|
683
|
-
const mainSegments = fullSegments.filter((s) => !isInterceptSegment(s));
|
|
684
|
-
|
|
685
|
-
// Prepare new tree (await loader data resolution)
|
|
686
|
-
const renderOptions = {
|
|
687
|
-
isAction: true,
|
|
688
|
-
interceptSegments:
|
|
689
|
-
interceptSegments.length > 0 ? interceptSegments : undefined,
|
|
690
|
-
};
|
|
691
|
-
const newTree = await renderSegments(mainSegments, renderOptions);
|
|
692
|
-
|
|
693
|
-
// Re-check if user navigated away (could happen during async wait)
|
|
694
|
-
const currentPathnameNow = window.location.pathname;
|
|
695
|
-
if (currentPathnameNow !== actionStartPathname) {
|
|
696
|
-
console.log(
|
|
697
|
-
`[Browser] User navigated during UI update scheduling, skipping`
|
|
698
|
-
);
|
|
699
|
-
handle.complete(returnData);
|
|
700
|
-
return returnData;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Verify the store's current key still matches what we captured at action start
|
|
704
|
-
// If they differ, user navigated away and we should NOT cache under the old key
|
|
705
|
-
const currentKeyNow = store.getHistoryKey();
|
|
706
|
-
if (currentKeyNow !== currentKey) {
|
|
707
|
-
console.log(
|
|
708
|
-
`[Browser] History key changed during action (${currentKey} -> ${currentKeyNow}), skipping cache update`
|
|
709
|
-
);
|
|
710
|
-
handle.complete(returnData);
|
|
711
|
-
return returnData;
|
|
712
645
|
}
|
|
713
646
|
|
|
714
|
-
startTransition(() => {
|
|
715
|
-
onUpdate({ root: newTree, metadata: metadata! });
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
// Update store state
|
|
719
|
-
store.setSegmentIds(matched);
|
|
720
|
-
const currentHandleData = eventController.getHandleState().data;
|
|
721
|
-
store.cacheSegmentsForHistory(currentKey, fullSegments, currentHandleData);
|
|
722
|
-
store.markCacheAsStaleAndBroadcast();
|
|
723
|
-
|
|
724
|
-
console.log(`[Browser] Normal - Returning to React:`, returnData);
|
|
725
647
|
handle.complete(returnData);
|
|
726
648
|
return returnData;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
throw new Error(
|
|
730
|
-
`[Browser] Full update after action is not supported yet`
|
|
731
|
-
);
|
|
649
|
+
} finally {
|
|
650
|
+
handle[Symbol.dispose]();
|
|
732
651
|
}
|
|
733
652
|
}
|
|
734
653
|
|
|
@@ -743,18 +662,6 @@ export function createServerActionBridge(
|
|
|
743
662
|
}
|
|
744
663
|
deps.setServerCallback(handleServerAction);
|
|
745
664
|
isRegistered = true;
|
|
746
|
-
console.log("[Browser] Server action callback registered");
|
|
747
|
-
},
|
|
748
|
-
|
|
749
|
-
/**
|
|
750
|
-
* Unregister the server action callback
|
|
751
|
-
*/
|
|
752
|
-
unregister(): void {
|
|
753
|
-
if (!isRegistered) {
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
isRegistered = false;
|
|
757
|
-
console.log("[Browser] Server action bridge unregistered");
|
|
758
665
|
},
|
|
759
666
|
};
|
|
760
667
|
}
|