Skip to content

feat: Extensible Routing - #260

Open
ruchamahabal wants to merge 36 commits into
frappe:developfrom
ruchamahabal:extensible-routing
Open

ruchamahabal wants to merge 36 commits into
frappe:developfrom
ruchamahabal:extensible-routing

Conversation

@ruchamahabal

Copy link
Copy Markdown
Member

No description provided.

A frappe app registers a function per studio app in hooks.py; its dict is
rendered into the app page as window.boot before the first navigation, and
the editor fetches the same dict via studio.api.get_app_boot for the canvas.
- Support router.ts with extendRoute, router options to be passed to createRouter, and setup hooks
- Load router configuration before initial navigation in preview and production
- Resolve aliased Studio pages by page identity for aliasing to work
- Add router discovery tests
Custom (DB) apps get the same router hook as standard apps through a
router_script Code field on Studio App. It holds the router.ts object
without import/export, is served as window.router_script and runs once
before the first navigation. The editor's Code tab gets a Page/Router
toggle. Enabling app export moves the script into router.ts and
disabling it restores the field.
@ruchamahabal
ruchamahabal marked this pull request as ready for review September 30, 2026 16:38
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[High risk] Adds router script feature with new runtime configuration.

Not ready to merge: two previously reported router failures remain outstanding.

Reviews (13) · Last reviewed commit: "refactor: remove unnecessary tests"

Comment thread frontend/src/stores/codeStore.ts Outdated
Comment thread frontend/src/pages/AppContainer.vue Outdated
mode (called before the export folder is deleted on un-export)."""
if not os.path.exists(self.get_router_file_path()):
return
self.router_script = unwrap_router_script(frappe.read_file(self.get_router_file_path()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Imported router stops running. If a standard app’s router.ts imports modules, un-exporting stores those imports in router_script. The custom-app renderer evaluates that field with new Function, where imports are invalid, so the router configuration stops running. Convert or reject module-based files before switching modes.

Knowledge Base Used: Build, export, and sync

Prompt To Fix With AI
This is a comment left during a code review.
Path: studio/studio/doctype/studio_app/studio_app.py
Line: 162

Comment:
**Imported router stops running.** If a standard app’s `router.ts` imports modules, un-exporting stores those imports in `router_script`. The custom-app renderer evaluates that field with `new Function`, where imports are invalid, so the router configuration stops running. Convert or reject module-based files before switching modes.

**Knowledge Base Used:** [Build, export, and sync](https://app.greptile.com/frappe/-/custom-context/knowledge-base/frappe/studio/-/docs/build-export-and-sync.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread studio/build.py Outdated
Comment thread frontend/src/components/RouterScript.vue Outdated
- complete page titles inside route.name === "…" and name: "…"
- complete members of router, the page route in extendRoute, route.meta and guard params like to/from, read from a real router built from the app's pages
- complete config keys: routerOptions and setup, and createRouter options inside routerOptions
- warn after saving a router script that names no page
- open router.ts from the file explorer in the router editor
Comment thread frontend/src/utils/routerScriptPageNames.ts Outdated
Comment thread studio/studio/doctype/studio_app/studio_app.py
Comment thread frontend/src/components/RouterScript.vue
Comment thread frontend/src/router/app_router.ts
Comment thread frontend/src/renderer.ts
await Promise.all([registerCustomVueComponents(frappeApp), registerStudioPageScripts(frappeApp)])
}
// installing the router runs the first navigation, so the app's guards must already be in place
app.use(await createAppRouter(await loadRouterConfig()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Router failures leave blank pages. If a saved router script throws or router.ts fails to load, startup now stops before #app mounts, leaving visitors with a blank page instead of an error. Restore a visible startup error in both this renderer and the generated renderer.

Knowledge Base Used: Generated app runtime

Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/renderer.ts
Line: 42

Comment:
**Router failures leave blank pages.** If a saved router script throws or `router.ts` fails to load, startup now stops before `#app` mounts, leaving visitors with a blank page instead of an error. Restore a visible startup error in both this renderer and the generated renderer.

**Knowledge Base Used:** [Generated app runtime](https://app.greptile.com/frappe/-/custom-context/knowledge-base/frappe/studio/-/docs/generated-app-runtime.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread frontend/src/components/RouterScriptButton.vue
self.assertEqual(app.app_title, "My Build App")
self.assertEqual(app.route, "my-build-app")

def test_export_router_script(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Renderer context tests removed. Please restore the tests for router_file and router_script. They were the only tests checking the mode-specific values passed to the renderer; the remaining router test covers export instead. Without them, this routing handoff can regress without a test failure.

Prompt To Fix With AI
This is a comment left during a code review.
Path: studio/studio/doctype/studio_app/test_studio_app.py
Line: 26

Comment:
**Renderer context tests removed.** Please restore the tests for `router_file` and `router_script`. They were the only tests checking the mode-specific values passed to the renderer; the remaining router test covers export instead. Without them, this routing handoff can regress without a test failure.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

1 participant