Skip to content

Commit 439bc4c

Browse files
Revert "fix(plugin-history-sync): revive journaled loader data"
This reverts commit 4658829.
1 parent c120559 commit 439bc4c

3 files changed

Lines changed: 8 additions & 121 deletions

File tree

extensions/plugin-history-sync/src/HistoryEntryJournal.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
identityEquals,
55
identityOfState,
66
} from "./BrowserHistoryEntryModel";
7-
import { reviveState, type State } from "./historyState";
7+
import type { State } from "./historyState";
88

99
const JOURNAL_STORAGE_KEY = "@stackflow/plugin-history-sync::entry-journal";
1010
const JOURNAL_FORMAT_VERSION = 1;
@@ -150,10 +150,6 @@ export class HistoryEntryJournal {
150150
}
151151

152152
const entries = new Map(payload.entries);
153-
for (const record of entries.values()) {
154-
reviveState(record.state);
155-
}
156-
157153
const currentRecord = entries.get(expectedIndex);
158154

159155
if (

extensions/plugin-history-sync/src/historyState.ts

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -23,83 +23,6 @@ interface SerializedState {
2323
flattedState: string;
2424
}
2525

26-
type SerializedInspectablePromise =
27-
| {
28-
status: "pending";
29-
}
30-
| {
31-
status: "fulfilled";
32-
value: unknown;
33-
}
34-
| {
35-
status: "rejected";
36-
reason: unknown;
37-
};
38-
39-
type SyncInspectablePromiseLike<T> = Promise<T> & SerializedInspectablePromise;
40-
41-
function isRecord(input: unknown): input is Record<string, unknown> {
42-
return typeof input === "object" && input !== null;
43-
}
44-
45-
function isSerializedInspectablePromise(
46-
input: unknown,
47-
): input is SerializedInspectablePromise {
48-
if (!isRecord(input) || typeof input.status !== "string") {
49-
return false;
50-
}
51-
52-
return (
53-
input.status === "pending" ||
54-
input.status === "fulfilled" ||
55-
input.status === "rejected"
56-
);
57-
}
58-
59-
function reviveInspectablePromise(
60-
input: SerializedInspectablePromise,
61-
): SyncInspectablePromiseLike<unknown> {
62-
if (input.status === "fulfilled") {
63-
return Object.assign(Promise.resolve(input.value), {
64-
status: input.status,
65-
value: input.value,
66-
});
67-
}
68-
69-
if (input.status === "rejected") {
70-
const promise = Promise.reject(input.reason);
71-
void promise.catch(() => undefined);
72-
73-
return Object.assign(promise, {
74-
status: input.status,
75-
reason: input.reason,
76-
});
77-
}
78-
79-
return Object.assign(new Promise<never>(() => undefined), {
80-
status: input.status,
81-
});
82-
}
83-
84-
function reviveActivityContext(input: unknown): void {
85-
if (!isRecord(input) || !("loaderData" in input)) {
86-
return;
87-
}
88-
89-
const loaderData = input.loaderData;
90-
91-
if (isSerializedInspectablePromise(loaderData)) {
92-
input.loaderData = reviveInspectablePromise(loaderData);
93-
}
94-
}
95-
96-
export function reviveState(state: State): State {
97-
reviveActivityContext(state.activity.context);
98-
reviveActivityContext(state.activity.enteredBy.activityContext);
99-
100-
return state;
101-
}
102-
10326
function serializeState(state: State): SerializedState {
10427
return {
10528
_TAG: STATE_TAG,
@@ -125,9 +48,7 @@ function isSerializedState(input: unknown): input is SerializedState {
12548

12649
export function parseState(input: unknown): State | null {
12750
try {
128-
return isSerializedState(input)
129-
? reviveState(parse(input.flattedState))
130-
: null;
51+
return isSerializedState(input) ? parse(input.flattedState) : null;
13152
} catch {
13253
return null;
13354
}

extensions/plugin-history-sync/src/historySyncPlugin.blocker.spec.tsx

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @jest-environment jsdom */
2-
import { type ActivityLoaderArgs, defineConfig } from "@stackflow/config";
2+
import { defineConfig } from "@stackflow/config";
33
import type { Stack, StackflowActions } from "@stackflow/core";
44
import {
55
type BlockedNavigation,
@@ -9,7 +9,7 @@ import {
99
} from "@stackflow/plugin-blocker";
1010
import { basicRendererPlugin } from "@stackflow/plugin-renderer-basic";
1111
import type { StackflowReactPlugin } from "@stackflow/react";
12-
import { stackflow, useLoaderData } from "@stackflow/react";
12+
import { stackflow } from "@stackflow/react";
1313
import { act, cleanup, render } from "@testing-library/react";
1414
import { createBrowserHistory } from "history";
1515
import { historySyncPlugin } from "./historySyncPlugin";
@@ -43,49 +43,19 @@ type SessionStorageAccess = SessionStorageShim | null | "throw";
4343
let currentBlocker: BlockerControls | null = null;
4444
let restoreSessionStorage: (() => void) | null = null;
4545

46-
function homeLoader() {
47-
return {
48-
cards: ["home"],
49-
};
50-
}
51-
52-
function articleLoader({ params }: ActivityLoaderArgs<"Article">) {
53-
return {
54-
recommenderCards: [params.articleId],
55-
};
56-
}
57-
5846
function Home() {
59-
const { cards } = useLoaderData<typeof homeLoader>();
60-
61-
return (
62-
<div data-testid="activity">
63-
home
64-
{cards.map((card) => (
65-
<span key={card}>{card}</span>
66-
))}
67-
</div>
68-
);
47+
return <div data-testid="activity">home</div>;
6948
}
7049

7150
function Article() {
72-
const { recommenderCards } = useLoaderData<typeof articleLoader>();
73-
7451
useBlocker({
7552
shouldBlock: (action) => currentBlocker?.shouldBlock(action) ?? false,
7653
onBlocked: (blockedNavigation, actions) => {
7754
currentBlocker?.onBlocked(blockedNavigation, actions);
7855
},
7956
});
8057

81-
return (
82-
<div data-testid="activity">
83-
article
84-
{recommenderCards.map((card) => (
85-
<span key={card}>{card}</span>
86-
))}
87-
</div>
88-
);
58+
return <div data-testid="activity">article</div>;
8959
}
9060

9161
function path(browserWindow: Window) {
@@ -379,8 +349,8 @@ async function renderHarness({
379349
const config = defineConfig({
380350
transitionDuration: 0,
381351
activities: [
382-
{ name: "Home", route: "/home", loader: homeLoader },
383-
{ name: "Article", route: "/articles/:articleId", loader: articleLoader },
352+
{ name: "Home", route: "/home" },
353+
{ name: "Article", route: "/articles/:articleId" },
384354
],
385355
});
386356

0 commit comments

Comments
 (0)