[pull] main from tinacms:main#213
Merged
Merged
Conversation
## Summary Closes #6503. This PR makes media operations branch-aware end-to-end: 1. **Forward the branch on every cloud media call.** `TinaMediaStore`'s `upload_url`, `list`, and `delete` requests now carry `?branch=<encodedBranch>`, so once an app opts into branch-aware media those operations are scoped to the editor's current branch instead of always hitting production. 2. **Fix staging URL handling for multi-segment branches.** `@tinacms/graphql`'s media URL resolver now formats staging URLs as `/__staging/<branch>/__file/<path>` instead of `/__staging/<encoded-branch>/<path>`. The previous form broke for branches containing `/` (e.g. `feat/my-branch`) because CloudFront decodes paths before downstream components see them — the S3 write key (with a literal `%2F`) wouldn't match the decoded read path. The `__file` delimiter lets the branch contribute its natural `/` segments while still marking where the file path begins. 3. **Refresh from the server after upload.** The media manager now drops its locally-constructed entries and re-fetches the list, since the server is the source of truth for the canonical `src` URL (including the staging-branch path when applicable). Constructing it on the client would mean mirroring the server's branch-aware path logic plus the per-stage CDN host, which is fragile to keep in sync. ### Branch-forwarding details - `persist_cloud()` — appends `?branch=<encodedBranch>` to the `upload_url` request, then returns `[]` so the media manager's refresh path runs (see point 3 above) - `list()` cloud branch — appends `&branch=<encodedBranch>` to the list URL - `delete()` cloud branch — appends `?branch=<encodedBranch>` to the delete URL `this.api.branch` is already URL-encoded by [`Client.setBranch()`](https://github.com/tinacms/tinacms/blob/main/packages/tinacms/src/internalClient/index.ts#L167). A new private `encodedBranchParam()` helper decodes then re-encodes at the use site so the value is always single-encoded, even if the URL containing it is later re-processed. The local-mode code paths (`persist_local`, the local-mode list branch, the local-mode delete branch) are untouched. Also reserves an optional `rename?(from: string, to: string): Promise<Media>` hook on the `MediaStore` interface as a future extension point — no implementation in `TinaMediaStore`, no surfacing in `MediaManager`. ## Backward compatibility Older assets-api versions ignore unknown query parameters, so this can ship before [tinacms/tinacloud#3330](tinacms/tinacloud#3330) lands. When the flag isn't enabled on an app, the server's [`isBranchRequest()`](https://github.com/tinacms/tinacloud/blob/main/js/assets-api/src/api/koa-admin.ts#L16) helper falls through to production behaviour — and that fall-through is regression-tested for all three endpoints by [tinacms/tinacloud#3472](tinacms/tinacloud#3472). ## Test plan - [x] `pnpm --filter tinacms build` — clean - [x] `pnpm --filter tinacms test` — 321 passed, 5 skipped (no regressions) - [x] Manual diff inspection: each of the three cloud URLs now ends with `?branch=…` or `&branch=…` exactly once; local-mode branches are untouched - [x] Encoding round-trip: `feat/my-branch` (stored as `feat%2Fmy-branch`) decodes to `feat/my-branch` and re-encodes back to `feat%2Fmy-branch` --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Jack Pettit [SSW] <57518417+JackDevAU@users.noreply.github.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )