Commit Graph
6 Commits
Author SHA1 Message Date
Joshen Lim 4a73166675 Add support for downloading edge functions when file size exceeds max cap (#53709)
## Context

Just creating a separate PR cause I messed up the [previous
one](https://github.com/supabase/supabase/pull/53453) with a bad merge 🫠
Also changed the implementation to no longer use `@deno/eszip`.

For edge functions, functions which exceed 5MB cannot be fetched and
displayed in the dashboard editor (API will return a 507). The CTA we
give to users is to download the function via the CLI, but this PR
explores allowing users to download their edge functions via the browser
still, by calling `/v1/functions/slug/body` without the
`multi-part/data` header. This returns the function in a raw eszip
stream which we're then parsing using a custom reader

We'll do this via the "Download as ZIP" CTA here - but this way of
downloading only kicks in if the GET Edge Function body endpoint returns
a 507. Otherwise it'll just be status quo where we bundle the files that
were already fetched to render in the browser into a ZIP file.
<img width="343" height="186" alt="image"
src="https://github.com/user-attachments/assets/4ffc9fee-7e6d-46a6-bdbe-294610abc802"
/>

Also updated the warning for 507s:
- To use a normal admonition instead of `AlertError` since its
technically not an issue
- To avoid rendering the API error message in this case specifically as
the API message contains "Use multipart instead" which isn't relevant to
the dashboard from a user's POV
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/8242a875-f142-419d-81f0-0dbc30807f87"
/>

## To test

- [ ] Upload an edge function of size larger than 5MB to a staging
project via the CLI
- [ ] Verify that there's an Admonition for the large function instead
of an error
- [ ] Verify that you can still download the edge function via the
Download button (Which triggers a POST /body request without multipart)
2026-11-23 10:59:57 +07:00
Drew McLellan b74d799c3d fix(studio): sort edge function files by name and select the entrypoint by default (#51796)
## Problem

The file list in an Edge Function's code view is shown in the order the
Management API returns it (roughly `created_at` order), not sorted by
name. Users expect name order, as in VS Code.

Resolves FE-2799

## Solution

- `formatFunctionBodyToFiles` now sorts files by their displayed name
before assigning ids, using a case-insensitive numeric comparison
(`file2` before `file10`). The list is flat, so there is no folder
grouping.
- Sorting would have changed which file opens first, so the code page
now selects the function's entrypoint file by default.
`getDefaultSelectedFileId` matches the entrypoint's basename, then falls
back to `index.ts`, then to the first file. The entrypoint isn't always
`index.ts`: the docs allow any `.ts`, `.js`, `.tsx`, `.jsx` or `.mjs`
file.
- The shared `FileExplorerAndEditor` and the new-function page are
unchanged. The code page passes the selection through the explorer's
existing `selectedFileId` / `setSelectedFileId` props.
- Files added or renamed in the editor keep their position until the
next load.

Before:
<img width="259" height="370" alt="Screenshot 2026-10-15 at 16 44 50"
src="https://github.com/user-attachments/assets/611fe2b9-5676-496a-85a9-e50032708c7a"
/>

After:
<img width="259" height="371" alt="Screenshot 2026-10-15 at 16 35 19"
src="https://github.com/user-attachments/assets/7f433661-ef34-4e3f-9143-afc67be1b30a"
/>


## Review instructions

1. Open an Edge Function's Code tab for a function with several files,
for example `utils.ts`, `index.ts`, `deno.json`.
2. Confirm the files are listed alphabetically and that `index.ts` is
selected on load.
3. For a function with a custom entrypoint (for example `main.ts`),
confirm that file is selected on load.
4. Run `pnpm test:studio -- components/interfaces/EdgeFunctions`.
2026-10-16 13:28:59 +08:00
Joshen Lim 957f84b17c Joshenlim/fe 4348 find an alternative to the jsr stdpath dependency (#50111)
## Context

Drops the `@std/path` dependency which is used in `EdgeFunctions.utils`
as `npm.jsr.io` was putting up a Cloudflare bot challenge on some
connections which blocks `pnpm install`. Instead, opting to directly
port the exact required methods as self-contained functions. Also added
some unit tests to check that UI behaviour remains status quo.

## To test: 
Important to test that everything in the edge functions UI remains
status quo
- [ ] Open an existing edge function with a single root-level file -
should load as expected
<img width="310" height="176" alt="image"
src="https://github.com/user-attachments/assets/4d724ab0-33bb-4093-a574-52984b2743fd"
/>
- [ ] Open (or create) an edge function with nested folders - confirm
file paths in the editor are shown correctly
  - Can create nested folders by using `../` as such
<img width="319" height="228" alt="image"
src="https://github.com/user-attachments/assets/dd345b1f-7c45-47e9-975c-f2f2e53a0106"
/>
- [ ] Similarly, download the edge function as ZIP to verify that the
nested folders are all correctly located
- [ ] Open a function with `import_map.json` - confirm still detected as
import map through the network tab GET request for the edge function
code (Examples here with and without import map)
<img width="333" height="245" alt="image"
src="https://github.com/user-attachments/assets/90fc90e3-4a62-493b-9246-ed7e3b662e96"
/>
<img width="290" height="237" alt="image"
src="https://github.com/user-attachments/assets/2f692362-c9d4-4394-bc5a-4f84ab5fb6f1"
/>
- [ ] Deploy a new function via the editor
- [ ] Update an existing function via the editor (Test adding new files
etc)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved Edge Functions file path handling across supported
application environments.
- Nested entrypoints, URL-based entrypoints, root-level files, and
unmatched paths are now handled consistently.
- Generated files retain their content and receive sequential
identifiers reliably.
- Improved compatibility when processing and displaying files in
different application environments.

- **Tests**
- Added coverage for entrypoint path formatting, relative paths,
fallback behavior, unchanged paths, and identifier assignment.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-09 14:37:32 +08:00
f293036ec7 Add UX guardrails for edge functions RE unsaved and unimported files (#41921)
* Add UX guardrails for edge functions RE unsaved and unimported files

* useLatest on hasUnsavedChanges

* Remove checking of unimported files + add VS code like indicator for modified and unsaved files

* Nit

* Fix TS

* Fix

* nit

* Fixes

* Nit

* move hasUnsavedChanges on demand

* code rabbit nit

* code rabbit nit 2

* prettier

---------

Co-authored-by: Alaister Young <a@alaisteryoung.com>
Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-01-22 13:31:28 +08:00
Lakshan Perera b698230349 fix: allow using .tsx and .jsx as entrypoints in functions (#40885) 2025-11-28 14:21:04 +08:00
Lakshan PereraandJoshen Lim 426c371d59 fix: correctly set entrypoint, import map path and static patterns for new functions (#40368)
* fix: correctly set entrypoint, import map path and static patterns for new functions

* Smol refactor

* Use TimestampInfo for last updated column in edge functions

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-11-12 17:13:22 +08:00