feat: Extensible Routing - #260
ruchamahabal wants to merge 36 commits into
Conversation
e1c8ff4 to
3ea10fe
Compare
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
…arn on withheld keys
… parsing object literals
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.
…page and router scripts
|
| 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())) |
There was a problem hiding this 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
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.- 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
…ater as one static file
… the page title completions
…ws before mount like a Vue app
| 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())) |
There was a problem hiding this 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
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.| self.assertEqual(app.app_title, "My Build App") | ||
| self.assertEqual(app.route, "my-build-app") | ||
|
|
||
| def test_export_router_script(self): |
There was a problem hiding this 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.
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!
741ea2d to
0ead0e7
Compare
No description provided.