experiment(notebooks): webapp Query editor as same-document widget#3473
Draft
mariusandra wants to merge 1 commit into
Draft
experiment(notebooks): webapp Query editor as same-document widget#3473mariusandra wants to merge 1 commit into
mariusandra wants to merge 1 commit into
Conversation
…dget Wires the PostHog webapp's REAL insight editor (built as a standalone widget bundle from the posthog repo's new frontend/src/widgets entry) in as the EditComponent for notebook Query nodes. Same document, no iframe: the bundle carries its own React 18 + kea and renders into a shadow root, the toolbar pattern applied to the query editor. - widgets/widgetLoader.ts: loads window.PostHogWidgets once via dynamic import; experiment toggle via localStorage key posthog.notebooks.widgetsUrl (e.g. http://localhost:8124/widgets.js). - widgets/QueryWidgetEdit.tsx: EditComponent bridging node.props.query <-> mountQueryEditor. Auth: apiHost from the auth store's cloud region, bearer tokens streamed through hostClient.auth.getValidAccessToken (also used as the widget's 401-refresh callback). Theme follows themeStore. - notebookRegistry.tsx: Query nodes get the widget edit panel (exclusiveEditPanel) when the toggle is set; JSON editor otherwise. - bootstrap.ts: POSTHOG_CODE_USERDATA_DIR override so a second dev instance can run side-by-side (single-instance lock lives in userData). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
React Doctor found 6 issues in 1 file · 3 errors & 3 warnings. Errors
3 warnings
Reviewed by React Doctor for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Experiment 3/3: shared widgets — the real insight editor in code, no iframe
Proves the toolbar pattern generalizes: the webapp's full editable Query/InsightViz editor (series row, math dropdown, full TaxonomicFilter, breakdown/filters) mounts same-document inside the code app — shadow root, its own React 18 + kea copy, coexisting with the React 19 tree with zero page errors — and round-trips query JSON to the host via
onQueryChange.What was verified
onQueryChange("total"→"dau"); live dark/light flip restyles even open popovers.mountQueryEditornext to the live React 19 UI, math change delivered"weekly_active"through the callback, cleanunmount().localStorage["posthog.notebooks.widgetsUrl"]).Why it was cheap
Upstream already had the seams: standalone OAuth mode in
lib/api.ts(one new in-memorysetOAuthSessionOverrideseam with a 401→refresh hook),FloatingContainerContextfor popover containment, tokens declared on:root, :host. OnlyuserLogic+teamLogicneeded hand-mounting; everything else self-mounts via keaconnect.Numbers & findings
widgets.js2.03 MB (603 KB gz) + CSS 137 KB gz; eager mount cost ~2.7 MB gz total; 186 lazy chunks for deferred surfaces (monaco etc.)./api/*(the toolbar depends on this).scope_object→ token auth supported.Dragons
kea-router listens to the host
window.history(no interference observed; "open in app" links would misroute); kea's localStorage plugin writes into the host origin; Max AI conversations polling runs even embedded; production serving story (bundle in app resources vs cloud static) undecided.🤖 Generated with Claude Code
Screenshots
The full TaxonomicFilter open inside the shadow root (dark theme), standalone harness:
Math dropdown, light theme — popovers positioned correctly inside the shadow root:
Mounted inside the running Electron app next to the React 19 UI (widget bottom-right):