Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(home): keep the one-time invitation link on screen after it is sent

nirholas994c9baa8e1d
diff --git a/src/home/members.js b/src/home/members.js
index f5fe5d215..7352534ac 100644
--- a/src/home/members.js
+++ b/src/home/members.js
@@ -66,6 +66,13 @@ export function householdPanel(home) {
body.style.marginTop = 'var(--space-sm)';
wrap.append(body);
+ // A sent invitation's link lives here, outside the body, because a refresh
+ // clears the body and the server keeps only a hash of the link. Rendering it
+ // inside the part that re-renders destroys the only copy that will ever
+ // exist, a second after showing it.
+ const sent = el('div');
+ wrap.append(sent);
+
let loaded = false;
const run = async () => {
clear(body);
@@ -75,7 +82,7 @@ export function householdPanel(home) {
try {
const data = await listHousehold(home.id);
clear(body);
- body.append(renderHousehold(home, data, run));
+ body.append(renderHousehold(home, data, run, sent));
} catch (err) {
clear(body);
body.append(noticeEl({
@@ -94,7 +101,7 @@ export function householdPanel(home) {
return wrap;
}
-function renderHousehold(home, data, rerender) {
+function renderHousehold(home, data, rerender, sent) {
const frag = document.createDocumentFragment();
const members = Array.isArray(data?.members) ? data.members : [];
const invites = Array.isArray(data?.invites) ? data.invites : [];
@@ -115,7 +122,7 @@ function renderHousehold(home, data, rerender) {
}
if (canAdminister) {
- frag.append(inviteForm(home, { assignable, rerender }));
+ frag.append(inviteForm(home, { assignable, rerender, sent }));
} else if (members.length === 1) {
// The only person in the household, and no way to change that from here.
// Saying who can is more useful than an empty panel.
@@ -491,7 +498,7 @@ function radio(name, value, text) {
return { input, label };
}
-function inviteForm(home, { assignable, rerender }) {
+function inviteForm(home, { assignable, rerender, sent }) {
const form = el('form', 'hm-panel');
form.style.marginTop = 'var(--space-sm)';
form.style.background = 'transparent';
@@ -554,8 +561,10 @@ function inviteForm(home, { assignable, rerender }) {
// The link is shown once, here, because the server keeps only a hash of
// it. Telling somebody to "check the invitations list for the link"
// would be a promise this system cannot keep, and it is shown whether or
- // not the email went out for exactly that reason.
- outcome.append(inviteLinkBlock(result?.invite_url, { emailed: result?.emailed === true, to: sentTo }));
+ // not the email went out for exactly that reason. It goes to `sent`,
+ // which the refresh below does not touch.
+ clear(sent);
+ sent.append(inviteLinkBlock(result?.invite_url, { emailed: result?.emailed === true, to: sentTo }));
rerender();
} catch (err) {
outcome.append(noticeEl({
diff --git a/tests/home-members-ui.test.js b/tests/home-members-ui.test.js
index 2a81155ae..f73a012b9 100644
--- a/tests/home-members-ui.test.js
+++ b/tests/home-members-ui.test.js
@@ -98,7 +98,9 @@ describe('the household panel renders what the server said', () => {
const panel = await open(roster({
members: [{ user_id: 'g', role: 'guest', scoped: true, scope: { mode: 'allow', areas: ['kitchen'], entities: [] }, email: '[email protected]', display_name: 'Sitter', can_manage: true }],
}));
- expect(panel.textContent).toContain('never be able to approve unlocking a door');
+ // Matched as a guarantee, not as a sentence: the copy is allowed to be
+ // reworded, the promise that a guest can never approve a door is not.
+ expect(panel.textContent).toMatch(/never\b[^.]*approve unlocking a door/);
expect(panel.textContent).toContain('Limited to 1 room');
});
diff --git a/tests/home-privacy.test.js b/tests/home-privacy.test.js
index 557972c33..87e52e944 100644
--- a/tests/home-privacy.test.js
+++ b/tests/home-privacy.test.js
@@ -37,12 +37,20 @@ import { CONNECT_DISCLOSURE, DISCLOSURES, VOICE_DISCLOSURE, disclosureById } fro
const MIGRATIONS_DIR = join(process.cwd(), 'api/_lib/migrations');
function homeMigrations() {
+ // Sorted, because the filenames are timestamps and the scans below read them
+ // the way Postgres applied them: in order, with a later statement winning.
return readdirSync(MIGRATIONS_DIR)
+ .sort()
.filter((f) => f.endsWith('.sql'))
.map((f) => ({ file: f, sql: readFileSync(join(MIGRATIONS_DIR, f), 'utf8') }))
.filter((m) => /create table (if not exists )?home_/i.test(m.sql) || /alter table home_/i.test(m.sql));
}
+/** The same SQL with its comments removed, so prose about a constraint is not read as one. */
+function withoutSqlComments(sql) {
+ return sql.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/--[^\n]*/g, '');
+}
+
/** Every `home_*` table any migration in the repo creates. */
function declaredHomeTables() {
const found = new Set();
@@ -318,15 +326,32 @@ describe('home privacy: retention bounds', () => {
// never heard of. Two of these shipped in this campaign
// (home_entity_grants.granted_by, home_layouts.updated_by), both invisible
// to a test that only deletes an owner's own data, because an owner's
- // homes cascade in the same statement. Every future one fails here.
- const offenders = [];
+ // homes cascade in the same statement. Both were then repaired by a later
+ // migration, which is why this reads the schema the way Postgres builds
+ // it rather than one file at a time: in apply order, with a later ALTER
+ // replacing what an earlier CREATE TABLE said about the same column, and
+ // with comments carrying no weight. Every future one fails here.
+ const constraints = new Map();
for (const { file, sql } of homeMigrations()) {
- for (const m of sql.matchAll(/references\s+users\s*\(\s*id\s*\)([^,\n)]*)/gi)) {
- if (!/on delete/i.test(m[1])) {
- offenders.push(`${file}: "references users(id)${m[1].trim()}"`);
- }
+ let table = null;
+ for (const line of withoutSqlComments(sql).split('\n')) {
+ const target = /(?:create|alter)\s+table\s+(?:if\s+(?:not\s+)?exists\s+)?([a-z0-9_]+)/i.exec(line);
+ if (target) table = target[1].toLowerCase();
+ if (!table || !/references\s+users\s*\(\s*id\s*\)/i.test(line)) continue;
+ // An ALTER names its column in `foreign key (col)`; a CREATE TABLE
+ // column definition opens the line with the column's own name.
+ const named = /foreign\s+key\s*\(\s*([a-z0-9_]+)\s*\)/i.exec(line) || /^\s*([a-z0-9_]+)\b/.exec(line);
+ if (!named) continue;
+ constraints.set(`${table}.${named[1].toLowerCase()}`, {
+ file,
+ text: line.trim(),
+ deletable: /on\s+delete/i.test(line),
+ });
}
}
+ const offenders = [...constraints]
+ .filter(([, c]) => !c.deletable)
+ .map(([column, c]) => `${column} (${c.file}): "${c.text}"`);
expect(
offenders,
`A home_* column references users(id) with no ON DELETE action, so an account that touched it can never be deleted. Choose CASCADE (the person's own row) or SET NULL (a record of an action that outlives the actor):\n ${offenders.join('\n ')}`,