Skip to content

Commit 9a37ed0

Browse files
committed
Removed custom chrome profile from commit to avoid issues
Updated scraper messaging to maeke sure messages register BEFORE db
1 parent 99c13ae commit 9a37ed0

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

entrypoints/content.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export default defineContentScript({
3232
matches: ["https://utdirect.utexas.edu/apps/degree/audits/*"],
3333
cssInjectionMode: "ui",
3434
async main(ctx) {
35+
// Register message handlers before asynchronous setup so background
36+
// scraper tabs always have a receiver when loading completes.
37+
startAuditContentController(document);
3538
await seedDatabase();
3639
loadFonts();
3740
setHeaderHeight();
@@ -48,7 +51,5 @@ export default defineContentScript({
4851
});
4952
banner.mount();
5053
}
51-
52-
startAuditContentController(document);
5354
},
5455
});

features/audit/audit-provider.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
getAuditHistory,
2323
renameAudit,
2424
saveAuditData,
25+
watchAuditData,
2526
watchAuditHistory,
2627
} from "@/lib/storage/audit-storage";
2728
import { createContext, useContext, useEffect, useMemo, useState } from "react";
@@ -128,6 +129,13 @@ export function AuditContextProvider({
128129
});
129130
}, []);
130131

132+
useEffect(() => {
133+
if (!currentAuditId) return;
134+
135+
setAuditData(null);
136+
return watchAuditData(currentAuditId, setAuditData);
137+
}, [currentAuditId]);
138+
131139
useEffect(() => {
132140
let cancelled = false;
133141
setLoaded(false);
@@ -166,11 +174,6 @@ export function AuditContextProvider({
166174
}, [currentAuditId, updateLastAuditId]);
167175

168176
const value = useMemo<AuditContextValue>(() => {
169-
const persist = async (auditId: string, updated: CachedAuditData) => {
170-
await saveAuditData(auditId, updated);
171-
setAuditData(updated);
172-
};
173-
174177
// currentAuditId and history are guaranteed non-null past the loading
175178
// guard below, which is the only path that renders this provider's value.
176179
return {
@@ -204,7 +207,7 @@ export function AuditContextProvider({
204207
if (!auditData || !currentAuditId) return false;
205208
const updated = moveCourseToSemester(auditData, courseId, semester);
206209
if (!updated) return false;
207-
await persist(currentAuditId, updated);
210+
await saveAuditData(currentAuditId, updated);
208211
return true;
209212
},
210213
addPlannedCourse: async (course, requirementTitle, ruleTitle) => {
@@ -216,7 +219,7 @@ export function AuditContextProvider({
216219
ruleTitle,
217220
);
218221
if (!result) return null;
219-
await persist(currentAuditId, result.audit);
222+
await saveAuditData(currentAuditId, result.audit);
220223
return result.courseId;
221224
},
222225
};
@@ -233,7 +236,9 @@ export function AuditContextProvider({
233236
updateLastAuditId,
234237
]);
235238

236-
if (!loaded || !currentAuditId || !history) return <LoadingPage />;
239+
if (!loaded || !currentAuditId || !history || !auditData) {
240+
return <LoadingPage />;
241+
}
237242

238243
return (
239244
<AuditContext.Provider value={value}>{children}</AuditContext.Provider>

lib/storage/audit-storage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ export async function getAuditData(
7070
return (result[key] as CachedAuditData | undefined) ?? null;
7171
}
7272

73+
export function watchAuditData(
74+
auditId: string,
75+
listener: (audit: CachedAuditData | null) => void,
76+
): () => void {
77+
return storage.watch<CachedAuditData>(
78+
`local:${AUDIT_DATA_PREFIX}${auditId}`,
79+
listener,
80+
);
81+
}
82+
7383
export async function getUncachedAuditIds(
7484
auditIds: string[],
7585
): Promise<string[]> {

wxt.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const profilePath = path.join(os.homedir(), ".chrome-extension-dev-profile");
88

99
export default defineConfig({
1010
modules: ["@wxt-dev/module-react"],
11-
webExt: {
12-
chromiumProfile: profilePath,
13-
keepProfileChanges: true,
14-
},
11+
// webExt: {
12+
// chromiumProfile: profilePath,
13+
// keepProfileChanges: true,
14+
// },
1515

1616
// Ensure UTF-8 encoding and strip invalid Unicode for Chrome extension compatibility
1717
hooks: {

0 commit comments

Comments
 (0)