Skip to content

chore(kea): migrate kea logic types to inline MakeLogicType blocks - #70885

Merged
mariusandra merged 5 commits into
masterfrom
typegen-inline
Jul 15, 2026
Merged

chore(kea): migrate kea logic types to inline MakeLogicType blocks#70885
mariusandra merged 5 commits into
masterfrom
typegen-inline

Conversation

@mariusandra

Copy link
Copy Markdown
Collaborator

Problem

Generated logicType.ts files are invisible during review (gitignored), add an import indirection to every logic, and make it hard to see what a logic exposes without regenerating types locally.
kea-typegen 3.8.0 introduced an inline mode that writes plain, readable interfaces directly above each kea() call instead, and 3.8.1 added inlinePaths so a repo this size can migrate directory by directory.

This PR is the first step of that migration, converting everything under frontend/src/scenes/notebooks.

Changes

  • .kearc gains "inlinePaths": ["./frontend/src/scenes/notebooks"] and kea-typegen is bumped to 3.8.1. Directories on that list get a generated block above each logic instead of a logicType.ts file; everything else keeps working exactly as before. Migrating another directory is just adding it to the list and running typegen:write.
  • All 17 notebooks logics now carry inline types:
// Generated by kea-typegen. DO NOT EDIT THIS BLOCK MANUALLY.
export interface notebookSceneLogicValues {
    notebook: NotebookType | null // notebookLogic
    notebookLoading: boolean // notebookLogic
    notebooksLoading: boolean // notebooksModel
    notebookId: string
    ...
}

// Generated by kea-typegen. DO NOT EDIT THIS BLOCK MANUALLY.
export interface notebookSceneLogicActions { ... }

export type notebookSceneLogicType = MakeLogicType<notebookSceneLogicValues, notebookSceneLogicActions>
  • Values and actions pulled in via connect are marked with a // sourceLogic comment.
  • Untyped selector combiner params got explicit annotations written into the source (e.g. (counter: number) => ...). MakeLogicType types combiner args as any, so without the annotations the inferred value types would silently degrade on later typegen runs.
  • Importers of the deleted type files now use import type { xxxLogicType } from './xxxLogic' (type-only, so the notebookLogicnotebookNodeLogic type references don't become runtime import cycles).
  • products/customer_analytics declares @tiptap/core as a "*" peer dependency (same as products/conversations): its regenerated accountNotebooksLogicType.ts references import("@tiptap/core").FocusPosition through a connected notebook action.
  • frontend/src/AGENTS.md documents the inline mode so agents don't hand-edit the generated blocks.

The blocks stay maintained by the usual commands (typegen:write, typegen:watch, CI typegen:check), and the comparison in kea-typegen 3.8.1 is formatting-insensitive, so oxfmt reflowing a block doesn't cause rewrite churn. Logics manually typed with kea<MakeLogicType<...>>() are left alone entirely, so hand-written types remain an option.

How did you test this code?

All automated, run locally by the agent:

  • pnpm --filter=@posthog/frontend typescript:check (tsgo) passes with 0 errors.
  • pnpm --filter=@posthog/frontend typegen:check with the published kea-typegen 3.8.1 exits 0, including after an oxfmt pass over the converted files (no rewrite loop).
  • All 36 jest suites under frontend/src/scenes/notebooks pass (507 tests).
  • The new kea-typegen behavior itself (inlinePaths, sticky detection, connected actions from MakeLogicType logics, formatter tolerance, selector annotation) is covered by unit tests in the kea-typegen repo (v3.8.1).

No runtime behavior changes intended; the diff is types, imports, and comments. I did not manually test the notebooks UI.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Built with Claude Code (Claude Fable 5). Marius drove the direction; Claude did the conversion and shipped kea-typegen 3.8.1 alongside it (inlinePaths, sticky inline detection, selector param annotation, formatter-tolerant comparison, and a semantic fallback in visitConnect).

Decisions worth knowing during review:

  • Connected actions from MakeLogicType logics were silently dropped by kea-typegen's syntactic actionCreators walk (mapped type, not a literal); the 3.8.1 semantic fallback fixes this for both inline and classic consumers. That fallback resolves types to their true declaration, which is why customer_analytics newly needs the @tiptap/core peer dep.
  • Selector combiner annotation exists because typegen infers value types from the combiners; under MakeLogicType the contextual types are gone, so the first regeneration after conversion would otherwise degrade values to any.
  • A stale local themeLogicType.ts orphan (logic moved to lib/logic in chore(toolbar): move themeLogic and dataThemeLogic to lib/logic #69134) surfaced during typechecking; deleted locally only, since these files are gitignored.

First step of migrating generated logicType.ts files to inline types,
using kea-typegen 3.8.1's new inlinePaths mode. Everything under
frontend/src/scenes/notebooks now carries a generated MakeLogicType
block above each kea() call instead of a separate logicType.ts file.
Connected values/actions are marked with their source logic and
selector combiner params carry explicit type annotations.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mariusandra mariusandra self-assigned this Jul 14, 2026
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

Bundle size — no change

Uncompressed size of every built .js bundle, compared against the base branch.

Total: 64.76 MiB · no change

No file changed by more than 1000 B.

Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report

Eager graph — within budget

How much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy import() / React.lazy chunks are not counted.

Root Eager (shipped) Δ vs base Budget
entry (logged-out pages, app bootstrap)
src/index.tsx
1.22 MiB · 22 files no change ███░░░░░░░ 28.4% of 4.29 MiB
authenticated shell (every logged-in page)
src/scenes/AuthenticatedShell.tsx
8.14 MiB · 2,977 files no change █████████░ 88.0% of 9.25 MiB

🟢 node_modules/monaco-editor/ stays out of src/index.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 node_modules/monaco-editor/ stays out of src/scenes/AuthenticatedShell.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx

Largest files eagerly shipped from src/index.tsx
Size File
126.8 KiB ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js
24.6 KiB ../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js
6.3 KiB ../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
4.5 KiB ../node_modules/.pnpm/@jspm+core@2.1.0/node_modules/@jspm/core/nodelibs/browser/process.js
3.9 KiB ../node_modules/.pnpm/scheduler@0.23.2/node_modules/scheduler/cjs/scheduler.production.min.js
1.4 KiB ../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
1.3 KiB src/RootErrorBoundary.tsx
912 B ../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js
789 B src/scenes/ChunkLoadErrorBoundary.tsx
762 B src/index.tsx
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
Size File
280.3 KiB ../node_modules/.pnpm/posthog-js@1.400.1/node_modules/posthog-js/dist/rrweb.js
267.7 KiB ../node_modules/.pnpm/@posthog+icons@0.38.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js
235.5 KiB src/taxonomy/core-filter-definitions-by-group.json
222.7 KiB ../node_modules/.pnpm/posthog-js@1.400.1/node_modules/posthog-js/dist/module.js
164.0 KiB src/queries/validators.js
154.3 KiB ../node_modules/.pnpm/re2js@0.4.1/node_modules/re2js/build/index.esm.js
126.8 KiB ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js
105.9 KiB src/lib/api.ts
93.3 KiB ../node_modules/.pnpm/prosemirror-view@1.40.1/node_modules/prosemirror-view/dist/index.js
92.7 KiB ../packages/quill/packages/quill/dist/index.js

Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479

Dist folder size — 🔺 +115.4 KiB (+0.0%)

Total size of the built frontend/dist folder (all assets), compared against the base branch.

Total: 1307.87 MiB · 🔺 +115.4 KiB (+0.0%)

Playwright — all passed

All tests passed.

View test results →

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🦔 Hogbox preview · ✅ ready

▶ Open the preview

🔑 Login test@posthog.com / 12345678 (demo data)
🧩 Running this PR's backend and frontend, on the PostHog :master base
🔗 Link stable across rebuilds — a re-push swaps the box underneath, the URL stays
🔒 Access tailnet only (PostHog VPN)
🛠️ Admin inspect & debug state in hogland
💤 Idle sleeps after ~30 min idle (snapshot to S3, zero node cost) and wakes on your next visit in ~30s, behind a brief "waking up" screen

commit 4530367 · box box-ec06d6ebc774 · ready in 777s (push → usable) · build log · rebuilds on every push, torn down on close

@mariusandra mariusandra changed the title chore(notebooks): migrate kea logic types to inline MakeLogicType blocks chore(kea): migrate kea logic types to inline MakeLogicType blocks Jul 14, 2026
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 14, 2026 20:53
@pr-assigner-resolver-posthog

Copy link
Copy Markdown

👀 Auto-assigned reviewers

These soft owners were skipped because they only have minor changes here. Nothing blocks merge, so self-assign if you'd like a look:

  • @PostHog/team-devex (AGENTS.md)
  • @PostHog/team-web-analytics (products/customer_analytics/**)

Soft owners come from CODEOWNERS-soft and each product's product.yaml. Generated files and lockfiles are ignored when deciding ownership.

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "chore(notebooks): migrate kea logic type..." | Re-trigger Greptile

kea-typegen 3.8.2: the generated block marker now reads "Update if
you're an agent, ignore if you're human", and inline Values/Actions
interfaces sort connected entries first (grouped by source logic,
alphabetical) followed by the logic's own entries alphabetically.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions
github-actions Bot requested a deployment to preview-pr-70885 July 14, 2026 21:07 In progress
… 3.8.2

The npm package resolves the repo TypeScript (6.0.3) as its peer
dependency, which prints optional properties differently than the 4.9.x
used during local development (callback?: fn vs callback: fn |
undefined). Regenerated with the published package so the blocks match
what CI produces.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 14, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@mariusandra
mariusandra requested review from a team and rafaeelaudibert July 14, 2026 21:38
@posthog

posthog Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Visual changes approved by @mariusandra — baseline updated in ab5dbe5.

View this run in PostHog

6 changed.

posthog Bot and others added 2 commits July 15, 2026 08:35
6 updated
Run: 60b582ff-3cbd-47a6-8c55-c84ba771023f

Co-authored-by: mariusandra <53387+mariusandra@users.noreply.github.com>
@mariusandra
mariusandra merged commit 79cffa7 into master Jul 15, 2026
225 checks passed
@mariusandra
mariusandra deleted the typegen-inline branch July 15, 2026 11:39
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 15, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-15 12:03 UTC Run
prod-us ✅ Deployed 2026-07-15 12:24 UTC Run
prod-eu ✅ Deployed 2026-07-15 12:28 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants