Skip to content

Html rendering arweave#2152

Merged
prxt6529 merged 7 commits intomainfrom
html-rendering-arweave
Mar 23, 2026
Merged

Html rendering arweave#2152
prxt6529 merged 7 commits intomainfrom
html-rendering-arweave

Conversation

@prxt6529
Copy link
Copy Markdown
Collaborator

@prxt6529 prxt6529 commented Mar 23, 2026

Summary by CodeRabbit

  • New Features

    • Added automatic fallback to alternative Arweave gateways when loading NFT content fails, improving content reliability
    • Implemented timeout-based fallback (8 seconds) for HTML and iframe content
  • Bug Fixes

    • Improved error handling for 3D model loading with fallback mechanisms

Signed-off-by: prxt6529 <prxt@6529.io>
Signed-off-by: prxt6529 <prxt@6529.io>
Signed-off-by: prxt6529 <prxt@6529.io>
Signed-off-by: prxt6529 <prxt@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 23, 2026

Warning

Rate limit exceeded

@prxt6529 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91b107c4-be9f-42d2-b0e8-c2564f8b2c83

📥 Commits

Reviewing files that changed from the base of the PR and between 101921a and dc7f1a1.

📒 Files selected for processing (3)
  • __tests__/components/nft-image/utils/animation-source.test.ts
  • components/nft-image/renderers/NFTHTMLRenderer.tsx
  • lib/media/arweave-gateways.ts
📝 Walkthrough

Walkthrough

This PR centralizes Arweave gateway management by introducing a new shared module (lib/media/arweave-gateways.ts), refactoring existing components and configurations to use it instead of hardcoded gateway logic. It updates NFT renderers with Arweave URL fallback mechanisms, enhances animation source resolution to respect HTML format metadata, and dynamically generates security policies and Next.js image configuration from the centralized gateway list.

Changes

Cohort / File(s) Summary
New Gateway Utilities Module
lib/media/arweave-gateways.ts
New module exporting gateway hostname list, canonicalization, CSP source generation, remote pattern generation, runtime host detection, and URL prefix stripping utilities.
NFT Renderer Fallback Integration
components/nft-image/renderers/NFTHTMLRenderer.tsx, components/nft-image/NFTModel.tsx
Added Arweave URL fallback cycling with timeout-based advancement in HTML renderer; added error event listener registration in model viewer component.
Animation Source Resolution
components/nft-image/utils/animation-source.ts, __tests__/components/nft-image/utils/animation-source.test.ts
Modified resolution logic to prioritize metadata.animation_details.format === "html" check, changing candidate ordering; added test case verifying HTML animation source priority.
Arweave Fallback Utilities Refactoring
components/nft-image/utils/arweave-fallback.ts, components/waves/memes/submission/constants/security.ts, components/waves/memes/submission/hooks/useArtworkSubmissionForm.ts
Delegated gateway hostname canonicalization and host classification to shared module; added exported fallback URL generation function; expanded MediaErrorEvent type to support iframe elements.
Interactive Media Submission Updates
components/waves/memes/MemesArtSubmissionFile.tsx
Updated user-facing validation messages for external HTML embedding to reference "approved IPFS or Arweave gateway" terminology; minor class name reordering.
Dynamic Security & Config Generation
config/securityHeaders.ts, config/nextConfig.ts
Generated Content-Security-Policy sources and Next.js image remote patterns dynamically from centralized gateway hostname list instead of hardcoded values.

Sequence Diagram

sequenceDiagram
    actor User
    participant NFTHTMLRenderer as NFT HTML<br/>Renderer
    participant State as Component<br/>State
    participant Iframe as Iframe<br/>Element
    participant Timeout as Timeout<br/>Handler
    participant Gateway as Arweave<br/>Gateway URLs

    User->>NFTHTMLRenderer: Mount component
    NFTHTMLRenderer->>Gateway: getArweaveGatewayFallbackUrls(src)
    Gateway-->>NFTHTMLRenderer: [url1, url2, url3, ...]
    NFTHTMLRenderer->>State: Initialize activeIndex=0, activeUrl=url1
    NFTHTMLRenderer->>Iframe: Render with activeUrl
    Timeout->>Timeout: Start IFRAME_FALLBACK_TIMEOUT_MS (8s)
    
    alt Iframe loads successfully
        Iframe->>NFTHTMLRenderer: onLoad event
        NFTHTMLRenderer->>State: Set didLoadCurrentUrl=true
        Timeout->>Timeout: Clear timeout
    else Timeout expires or error occurs
        Timeout->>NFTHTMLRenderer: Timeout callback fires
        NFTHTMLRenderer->>State: Increment activeIndex
        NFTHTMLRenderer->>State: Set activeUrl=next URL
        NFTHTMLRenderer->>Iframe: Remount with new src & key
        Timeout->>Timeout: Start new timeout for next URL
    end
    
    alt All URLs exhausted
        Iframe->>NFTHTMLRenderer: Final fallback or error state
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #2088: Modifies getResolvedAnimationSrc to respect metadata.animation_details.format === "html" when ordering resolution candidates, directly building on the same function updated in this PR.
  • PR #2026: Modifies Arweave fallback utilities in components/nft-image/utils/arweave-fallback.ts and renderer error handling, overlapping with the fallback integration work.
  • PR #1717: Modifies config/securityHeaders.ts Content-Security-Policy generation, directly related to the CSP source changes in this PR.

Suggested reviewers

  • simo6529
  • ragnep

Poem

🐰 Gateways once scattered, now unified and bright,
Arweave URLs fallback when first attempts take flight,
From config to renderers, a centralized way,
NFTs load with grace—eight seconds' delay!
HTML formats respected, security tight. 🎨✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Html rendering arweave' is vague and overly generic, using non-descriptive terms that don't clearly convey the specific changes made in this comprehensive changeset. Replace with a more descriptive title that captures the main focus, such as 'Add Arweave gateway fallback support for HTML NFT animations' or 'Implement Arweave gateway resilience for interactive media rendering'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch html-rendering-arweave

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: prxt6529 <prxt@6529.io>
Signed-off-by: prxt6529 <prxt@6529.io>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
__tests__/components/nft-image/utils/animation-source.test.ts (1)

91-103: Consider adding edge case test for HTML format with missing metadata URLs.

This test validates the happy path where metadata.animation_url exists. Consider adding a test case for when format === "html" but both metadata.animation and metadata.animation_url are empty/undefined to document the expected behavior (should return undefined per current implementation).

💡 Suggested additional test case
it("returns undefined for HTML format when metadata animation fields are empty", () => {
  const nft = createMockNFT({
    animation: "https://example.com/processed.html",
    metadata: {
      animation_details: { format: "html" },
      animation: "",
      animation_url: undefined,
    },
  });

  expect(getResolvedAnimationSrc(nft)).toBeUndefined();
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/components/nft-image/utils/animation-source.test.ts` around lines
91 - 103, Add a new unit test in animation-source.test.ts that constructs an NFT
(via createMockNFT) whose metadata.animation_details.format === "html" but has
both metadata.animation === "" and metadata.animation_url === undefined (while
top-level animation is present) and assert that getResolvedAnimationSrc(nft)
returns undefined; name it something like "returns undefined for HTML format
when metadata animation fields are empty" to document the edge case and ensure
the current behavior is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/nft-image/renderers/NFTHTMLRenderer.tsx`:
- Around line 77-86: The iframe is rendered with src={activeUrl} even when
activeUrl is undefined; update the NFTHTMLRenderer to only render the <iframe>
when activeUrl is defined (e.g., check activeUrl before returning the iframe) so
you don't pass undefined to the iframe src; keep existing handlers (onLoad
calling setDidLoadCurrentUrl and onError calling advanceToNextUrl) and retain
id/key props (props.id, props.nft) and provide a simple fallback UI or null when
activeUrl is falsy.

---

Nitpick comments:
In `@__tests__/components/nft-image/utils/animation-source.test.ts`:
- Around line 91-103: Add a new unit test in animation-source.test.ts that
constructs an NFT (via createMockNFT) whose metadata.animation_details.format
=== "html" but has both metadata.animation === "" and metadata.animation_url ===
undefined (while top-level animation is present) and assert that
getResolvedAnimationSrc(nft) returns undefined; name it something like "returns
undefined for HTML format when metadata animation fields are empty" to document
the edge case and ensure the current behavior is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e24afead-7a4e-44ad-9d5c-61a2fddd2554

📥 Commits

Reviewing files that changed from the base of the PR and between bdac63b and 101921a.

📒 Files selected for processing (11)
  • __tests__/components/nft-image/utils/animation-source.test.ts
  • components/nft-image/NFTModel.tsx
  • components/nft-image/renderers/NFTHTMLRenderer.tsx
  • components/nft-image/utils/animation-source.ts
  • components/nft-image/utils/arweave-fallback.ts
  • components/waves/memes/MemesArtSubmissionFile.tsx
  • components/waves/memes/submission/constants/security.ts
  • components/waves/memes/submission/hooks/useArtworkSubmissionForm.ts
  • config/nextConfig.ts
  • config/securityHeaders.ts
  • lib/media/arweave-gateways.ts

Comment thread components/nft-image/renderers/NFTHTMLRenderer.tsx Outdated
Signed-off-by: prxt6529 <prxt@6529.io>
@sonarqubecloud
Copy link
Copy Markdown

@prxt6529 prxt6529 merged commit 45ddab8 into main Mar 23, 2026
8 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 23, 2026
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.

2 participants