Skip to content

fix(hosting/photo-storage): restore asset-canister recipe and fix canister-ID discovery - #1464

Open
marc0olo wants to merge 2 commits into
masterfrom
fix/photo-storage-asset-canister-revert
Open

fix(hosting/photo-storage): restore asset-canister recipe and fix canister-ID discovery#1464
marc0olo wants to merge 2 commits into
masterfrom
fix/photo-storage-asset-canister-revert

Conversation

@marc0olo

Copy link
Copy Markdown
Member

Problem

Two independent bugs, analyzed in #1458 / #1459:

  1. Missing API: the certified-assets canister behind @dfinity/static-site exposes none of the legacy asset-canister API (list/store/create_batch/commit_batch) that AssetManager uses — programmatic uploads, the example's purpose, cannot work on it (confirmed against certified-assets.did).
  2. Broken canister-ID discovery: the dfx-era hostname regex captured "frontend.local" from icp-cli's name-based URL (frontend.local.localhost:8000) and Principal.fromText threw Invalid character: "." at module load → white screen.

Fix

  • Revert the recipe to @dfinity/asset-canister@v2.2.1 (interim per hosting/photo-storage broken on static-site recipe — revert to asset-canister interim, decide long-term fate #1459; comment in icp.yaml explains the deliberate exception so the next recipe sweep doesn't re-migrate it).
  • Replace the URL parsing with the ic_env cookie pattern from hello_world: safeGetCanisterEnv() provides PUBLIC_CANISTER_ID:frontend + IC_ROOT_KEY; agent uses window.location.origin. Works on both name-based and ID-based URLs, locally and on mainnet.
  • README: authorize command targets frontend (the actual canister name), deploy section points at the URL icp deploy prints, II link → developer docs.

Verification

Manual e2e (2026-07-30): gallery renders on http://frontend.local.localhost:8000, upload works after authorize, photos persist across reloads. See #1459 for the long-term decision (keep-legacy / repurpose / retire).

🤖 Generated with Claude Code

…ister-ID discovery

The example was broken twice over:

1. The switch to @dfinity/static-site (#1449) removed the legacy asset
   canister API (list/store/create_batch/commit_batch) that AssetManager
   from @icp-sdk/canisters/assets depends on — the app's entire purpose.
   Revert to @dfinity/asset-canister@v2.2.1, the only canister supporting
   programmatic uploads, with a comment explaining the exception (#1459).

2. The dfx-era canister-ID parsing broke on icp-cli's name-based frontend
   URLs (frontend.local.localhost) — Principal.fromText received
   "frontend.local" and threw at module load (white screen). Replace the
   hostname regex, ic0.app heuristic, and fetchRootKey() with the ic_env
   cookie pattern used by hello_world (safeGetCanisterEnv), which works on
   both URL forms and on mainnet.

Also fix the README authorize command (canister is named frontend, not
photo-storage) and point deploy instructions at the URL icp deploy prints.

Verified end-to-end locally: gallery renders, uploads work after
authorize, photos persist across reloads.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@marc0olo
marc0olo marked this pull request as ready for review July 30, 2026 13:35
@marc0olo
marc0olo requested a review from a team as a code owner July 30, 2026 13:35
@marc0olo
marc0olo requested a review from Copilot July 30, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the hosting/photo-storage example so programmatic uploads via AssetManager work again and the frontend reliably discovers its own canister ID regardless of whether the gateway URL is name-based or ID-based.

Changes:

  • Revert hosting/photo-storage back to the legacy @dfinity/asset-canister@v2.2.1 recipe (required for AssetManager APIs).
  • Replace hostname-regex canister-ID parsing with ic_env cookie discovery via safeGetCanisterEnv() and use window.location.origin for agent host.
  • Update README deployment guidance and authorization command to target the frontend canister.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
hosting/photo-storage/src/App.jsx Switches canister ID discovery to ic_env cookie and updates agent host/root key wiring.
hosting/photo-storage/README.md Updates deploy URL guidance and fixes authorization command + II docs link.
hosting/photo-storage/icp.yaml Reverts to the legacy asset-canister recipe with an explanatory comment linking the rationale/issue.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hosting/photo-storage/README.md Outdated
Comment thread hosting/photo-storage/src/App.jsx
…k, fix README filename

The ?canisterId= query-param fallback ran without the ic_env cookie and
therefore without the local root key — a half-broken path nothing uses
(the app is only ever served from the canister, which always sets the
cookie; there is no dev-server flow). Require the cookie and fail with a
clear error instead. Deliberately no fetchRootKey(): that is legacy
behavior we no longer recommend — the root key comes from the certified
ic_env cookie.

Also fix the README warning to reference src/App.jsx (renamed from
App.js in the Vite migration).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants