You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KZN-19663 - only persist and restore viewer paths for bundle apps - #46
The dev server reopened the viewer on "No app found with api_name embed." because .kizenapp/config.json had "lastPath": "/embed/sandbox".
Likely cause: a plugin floating frame that calls this.outputIframe(${this.location.origin}/embed/...) loads a second copy of the dev viewer inside the iframe, because in the dev viewer that origin is the viewer's own localhost. That nested copy treated embed as an app and saved its own path. The ticket author inferred this; it hasn't been reproduced end to end.
Changes
Persisting and restoring lastPath
shared/lib/lastPath.tsisAppPath: one rule for which paths count. A path matches /<apiName>/<tab>... only when apiName is an app in bundle.json. A bare /<app> is rejected.
Viewer (App.tsx): POSTs /api/last-path only when it is the top-level page (window.self === window.top) and on a known app route.
POST /api/last-path: ignores paths that aren't valid against outputDir/bundle.json, and still returns 200.
dev startup (resolveRestorableLastPath): drops an invalid lastPath and removes it from config.json, so a bad config fixes itself. The write is best-effort: a write failure never blocks startup.
Every Chrome launch (DevUI, including v): re-checks the saved path against the current bundle.json. An app removed by a rebuild now opens at /.
Viewer UI
One shared AppNotFound state for unknown app routes replaces the four per-page "No app found" cards. NavTabs are hidden for unknown apps.
A viewer loaded inside an iframe renders only its routed content (no header, tabs, sidebar or dialogs). At non-app paths it shows a short hint explaining that Kizen routes like /embed/... only exist in the Kizen app. The hint copy is a placeholder (marked in code).
A non-array bundle (/api/bundle serves {} when nothing is built) is treated as no apps. Before, it threw on /$apiName/... routes.
Sandbox floating frames now render in their own fixed inset-0 z-[15] layer:
Before, their BASE_Z (9000+) was trapped inside a wrapper with no z-index, so z-10 page elements painted over them. The routable-page slide-out panel's shadow showed as a faint vertical line across frames.
The trigger gutter keeps its original layer, so the header and NavTabs look as before.
Frames sit above page content and below toasts (z-20), tooltips, dialogs and dropdowns.
A frame dragged over the header or NavTabs now covers them.
Testing
pnpm typecheck, pnpm lint: clean.
pnpm test: 2185 passed (2157 before). New tests cover:
isAppPath
the /api/last-path route: /embed/... POSTs leave the ref and config.json untouched
the startup heal (unknown app, missing bundle, read-only config.json)
restorablePath reading the current bundle
The viewer has no test runner, so the iframe gate, not-found and hint rendering, and frame layering are covered only by typecheck, lint and the viewer build.
Not checked in a browser yet:
On plugin-kizen-ai, opening the chat frame doesn't change lastPath, and the frame shows the hint with no viewer chrome.
A hand-set "lastPath": "/embed/sandbox" opens at / and is removed from config.json on the next start.
The dev viewer saved every pathname to lastPath, including paths from a
viewer copy nested in a plugin iframe (e.g. /embed/ai-chat), so the next
dev start reopened "No app found with api_name embed".
- shared isAppPath rule: a path counts only when its first segment is an
app in bundle.json
- viewer saves its path only when top-level and on a known app route
- POST /api/last-path ignores paths that aren't bundle-app routes
- dev startup drops (and best-effort removes) an invalid lastPath; every
Chrome launch re-checks the saved path against the current bundle
- one shared not-found state for unknown app routes
- framed viewer copies render without viewer chrome and show a hint at
non-app paths
- sandbox floating frames get their own z-[15] layer so page content
(e.g. the routable-page slide-out panel) no longer paints over them
…the bundle query
- runBuild writes bundle.json via a same-directory temp file and rename, so
readers (last-path route, launch check) never see a partial file
- the viewer bundle query normalizes /api/bundle's {} to [], and App's
not-found / iframe gates key on data presence rather than isSuccess, so a
failed refetch with retained data can't mount pages on a non-array bundle
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Saved paths are checked for bundle membership but not valid tabs or nested segments, allowing invalid routes to survive startup healing and reopen in the not-found view.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Validate saved paths against complete router routes
shared/lib/lastPath.ts:34
With demo_app in the bundle, this also accepts /demo_app/not-a-tab and /demo_app/sandbox/extra, neither of which matches a route in viewer/src/router.tsx. Such saved paths survive startup healing and are restored into the router's not-found view. Check the tab and permitted nested segments as well as bundle membership.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The raw-prefix validation accepts traversal paths such as /demo_app/../embed/sandbox, which Chrome normalizes to an unknown-app route, causing startup failure.
isAppPath now requires URL parsing to leave the path unchanged, so a path
like /demo_app/../embed/sandbox (or a %2e%2e, query, hash or // variant)
can't pass the app check and then open a different page once Chrome
normalizes it.
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
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.
KZN-19663
The dev server reopened the viewer on "No app found with api_name embed." because
.kizenapp/config.jsonhad"lastPath": "/embed/sandbox".Likely cause: a plugin floating frame that calls
this.outputIframe(${this.location.origin}/embed/...)loads a second copy of the dev viewer inside the iframe, because in the dev viewer that origin is the viewer's own localhost. That nested copy treatedembedas an app and saved its own path. The ticket author inferred this; it hasn't been reproduced end to end.Changes
Persisting and restoring
lastPathshared/lib/lastPath.tsisAppPath: one rule for which paths count. A path matches/<apiName>/<tab>...only whenapiNameis an app inbundle.json. A bare/<app>is rejected.App.tsx): POSTs/api/last-pathonly when it is the top-level page (window.self === window.top) and on a known app route.POST /api/last-path: ignores paths that aren't valid againstoutputDir/bundle.json, and still returns 200.devstartup (resolveRestorableLastPath): drops an invalidlastPathand removes it fromconfig.json, so a bad config fixes itself. The write is best-effort: a write failure never blocks startup.DevUI, includingv): re-checks the saved path against the currentbundle.json. An app removed by a rebuild now opens at/.Viewer UI
AppNotFoundstate for unknown app routes replaces the four per-page "No app found" cards. NavTabs are hidden for unknown apps./embed/...only exist in the Kizen app. The hint copy is a placeholder (marked in code)./api/bundleserves{}when nothing is built) is treated as no apps. Before, it threw on/$apiName/...routes.fixed inset-0 z-[15]layer:BASE_Z(9000+) was trapped inside a wrapper with no z-index, soz-10page elements painted over them. The routable-page slide-out panel's shadow showed as a faint vertical line across frames.Testing
pnpm typecheck,pnpm lint: clean.pnpm test: 2185 passed (2157 before). New tests cover:isAppPath/api/last-pathroute:/embed/...POSTs leave the ref andconfig.jsonuntouchedconfig.json)restorablePathreading the current bundlelastPath, and the frame shows the hint with no viewer chrome."lastPath": "/embed/sandbox"opens at/and is removed fromconfig.jsonon the next start.