autoFocus does nothing on elements mounted after page load (no focus() on commit)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 42/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- react, typescript
Rechercherichtung
Start with the autoFocus handling in the attribute mapping in core/attributes.js under dist/, then find where elements are committed to the DOM in the source, since the fix needs a .focus() call on mount. Run the Vitest repro from the issue with jsdom and check that document.activeElement is the input after the button click. Done means that test passes and SSR output still renders the autofocus attribute.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Version: @tanstack/redact 0.2.4
autoFocus on an element that mounts after the initial page load never receives focus. Redact writes the autofocus attribute, but browsers only honour that attribute during the initial document load. React doesn't rely on the attribute: it calls element.focus() when an autoFocus element is committed (commitMount), so it works for elements that appear later (inline edit fields, a code input shown after "send code", fields inside popovers).
Looking at dist/, autofocus only appears in core/attributes.js (attribute name mapping); there is no .focus() call on mount.
Repro (Vitest + jsdom + Testing Library)
// @vitest-environment jsdom
import { render, fireEvent, act } from "@testing-library/react";
import * as React from "react";
function App() {
const [editing, setEditing] = React.useState(false);
return (
<div>
<button onClick={() => setEditing(true)}>Edit</button>
{editing && <input aria-label="name" autoFocus />}
</div>
);
}
it("focuses an autoFocus input that mounts after an update", async () => {
const { getByRole, getByLabelText } = render(<App />);
const button = getByRole("button");
button.focus();
fireEvent.click(button);
await act(async () => {});
expect(document.activeElement).toBe(getByLabelText("name"));
});
autofocus attribute on the input |
document.activeElement |
|
|---|---|---|
| React 19 | not set | INPUT ✅ |
| Redact 0.2.4 | set | BUTTON ❌ |
Same result in real browsers (Chromium, production build of a TanStack Start app): in a day picker, typing a value and pressing Enter mounts a note textarea with autoFocus; React focuses it, Redact leaves focus in the picker popup. Our e2e test for that flow fails 4/4 under Redact and passes under React.
Expected
Like React: when an element with autoFocus is inserted by a client render (including after hydration), call .focus() on it once it is in the document. Rendering the attribute in SSR output for the initial load is fine.
Found in three TanStack Start apps (base-ui/shadcn) while moving them to Redact: a login code field shown after the code is sent, inline edit inputs, and a note field in a picker all stopped getting focus.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 537
- Forks
- 22
- Ø Merge
- 11 Std. 28 Min.
- Gemergte PRs (30 T.)
- 34
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/redact
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
TanStack/redact#142 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
TanStack/redact#144 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
TanStack/redact#141 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in TanStack/redact
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
bug needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
DSpace/dspace-angular#6511 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: frontend area:byok bug severity:low
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
Phone app shows Unknown for a remote machine whose key changedEvtl. vergeben @janicduplessis hat das heute übernommen. Offenarea: mobile priority: P3 type: bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
appandflow/stim#5006 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Area - Local to Cloud Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
microsoft/vscode-mssql#23209 ·
Maintainer antworten meist innerhalb von 1 Tag