Skip to content

fix: change create a poll LIP fetch to cached runtime API call#712

Open
ECWireless wants to merge 3 commits into
mainfrom
562-lips-do-not-immediately-appear-in-create-a-poll
Open

fix: change create a poll LIP fetch to cached runtime API call#712
ECWireless wants to merge 3 commits into
mainfrom
562-lips-do-not-immediately-appear-in-create-a-poll

Conversation

@ECWireless

@ECWireless ECWireless commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Description

This updates Create Poll so eligible LIPs are loaded at runtime through a short-cached API route instead of being baked into the page with ISR. That makes new proposed LIPs appear after reload almost immediately, while preserving the existing filtering for LIPs that are proposed, not part of another LIP, and do not already have a poll.

Type of Change

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation update
  • style: Code style/formatting changes (no logic changes)
  • refactor: Code refactoring (no behavior change)
  • perf: Performance improvement
  • test: Adding or updating tests
  • build: Build system or dependency changes
  • ci: CI/CD changes
  • chore: Other changes

Related Issue(s)

Closes: #562

Changes Made

  • Moves Create Poll LIP loading from getStaticProps ISR to a runtime API route.
  • Adds GET /api/polls/lips with short CDN stale-while-revalidate caching.
  • Updates /voting/create-poll to fetch LIPs via SWR and show loading/error states.
  • Keeps existing filtering for proposed LIPs without existing polls.

Testing

  • Tested locally
  • Added/updated tests
  • All tests passing

How to test

  • Somewhat cumbersome to test
  • You could either temporarily add a new LIP on the official Livepeer repo, or you could fork the LIP repo and update the envs locally or in the preview
  • Considering that this is cumbersome, I am noting that this worked with a local build and a Vercel preview build using a forked LIP repo

Impact / Risk

Risk level: Low

Impacted areas: UI / API

User impact: Those trying to put their LIP on-chain through /voting/create-poll no longer have to wait until the site is redeployed to see their GitHub version of the proposal.

Rollback plan: Vercel rollback, then manual git revert.

Summary by CodeRabbit

  • New Features

    • Poll LIPs are now loaded on demand through the app, keeping the create-poll page up to date with the latest available proposals.
    • A new poll proposals API is available to power the voting flow with live data.
  • Bug Fixes

    • Improved handling of loading and error states on the create-poll page.
    • Prevents stale proposal data from being submitted when the underlying poll list changes.

Copilot AI review requested due to automatic review settings June 27, 2026 21:01
@ECWireless ECWireless linked an issue Jun 27, 2026 that may be closed by this pull request
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
explorer-arbitrum-one Ready Ready Preview, Comment Jun 28, 2026 12:31am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a getPollLips() function and associated types that query GitHub GraphQL for LIP files, fetch subgraph poll proposals, resolve IPFS content, and filter/sort results. A new Next.js API route (/api/polls/lips) exposes this at runtime. The create-poll page replaces getStaticProps with SWR consuming that route.

Poll LIPs Runtime Fetching

Layer / File(s) Summary
Types and getPollLips implementation
lib/api/types/get-poll-lips.ts, lib/api/poll-lips.ts
Defines PollLip and PollLips types. getPollLips() queries GitHub GraphQL for LIP files using GITHUB_ACCESS_TOKEN, fetches subgraph polls, resolves each proposal's IPFS content via catIpfsJson, builds a createdPolls exclusion list, then filters to "Proposed" LIPs with no part-of not yet polled, sorted by attributes.lip descending.
API route /api/polls/lips
pages/api/polls/lips.ts
GET-only handler that sets a Cache-Control: revalidate header, calls getPollLips(), and returns PollLips JSON or an externalApiError on failure.
create-poll page migrated to SWR
pages/voting/create-poll.tsx
Removes getStaticProps and static prop types; CreatePoll now calls useSWR<PollLips>("/polls/lips"). Adds an effect to clear selectedProposal on gitCommitHash change. Renders loading/error/data states from SWR response; GitHub "View Proposal" URL uses pollLips.projectOwner/projectName.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the bug, fix, issue link, key changes, testing, and risk in the expected template.
Linked Issues check ✅ Passed The changes satisfy #562 by loading LIPs at runtime with short caching so new proposals appear without redeploys.
Out of Scope Changes check ✅ Passed The PR appears focused on the Create Poll LIP loading flow and related API/data refactor only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly summarizes the main change: moving Create a Poll LIP fetching to a cached runtime API call.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 562-lips-do-not-immediately-appear-in-create-a-poll

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/api/poll-lips.ts`:
- Around line 82-110: The request-time flow in pollLips currently performs
GitHub, subgraph, and per-poll IPFS calls without any timeout or concurrency
control, so bound those upstream fetches and fail fast through the existing
error handling path. Update the polling logic around githubFetch,
createApolloFetch, and the Promise.all over pollsData.polls to use server-side
request timeouts and a capped IPFS concurrency strategy instead of unbounded
parallel requests. Keep the existing validation and error-throwing behavior, but
ensure slow or excessive upstream calls cannot hold the route until platform
timeout.
- Around line 140-142: The sorting in lips.sort inside poll-lips.ts is comparing
lip ids as strings, which causes lexicographic ordering instead of numeric
ordering. Update the comparator in the lips sorting logic to convert the
attributes.lip values to numbers before comparing so higher-numbered LIPs appear
first correctly in the Create Poll list. Keep the change localized to the
sorting expression used by the lips array and ensure it still handles missing
attributes safely.

In `@pages/api/polls/lips.ts`:
- Around line 17-23: The Cache-Control header is being applied before
getPollLips() succeeds, so externalApiError() can return a cacheable transient
failure. Move the getCacheControlHeader("revalidate") header assignment to after
getPollLips() succeeds in the lips API handler, or explicitly set no-store in
the catch path so failures from externalApiError are never cached. Use the
getPollLips and externalApiError flow in the lips route to place the fix
correctly.

In `@pages/voting/create-poll.tsx`:
- Around line 71-73: Keep the selected proposal anchored to a stable LIP
identifier instead of list indexes or gitCommitHash. Update the proposal
rendering in create-poll.tsx so the radio value/key and lookup use
lip.attributes.lip, and adjust the selectedProposal state to store that stable
id. In the create-poll selection flow and the related proposal list/radio
handlers, clear or remap the selection whenever the chosen LIP is no longer
present after SWR refresh or filtering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 90cb7289-dbca-448c-83ba-701c9c8cbb7b

📥 Commits

Reviewing files that changed from the base of the PR and between 2c37a7e and ed07d88.

📒 Files selected for processing (4)
  • lib/api/poll-lips.ts
  • lib/api/types/get-poll-lips.ts
  • pages/api/polls/lips.ts
  • pages/voting/create-poll.tsx

Comment thread lib/api/poll-lips.ts Outdated
Comment thread lib/api/poll-lips.ts Outdated
Comment thread pages/api/polls/lips.ts
Comment thread pages/voting/create-poll.tsx Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 moves “eligible LIPs” loading for /voting/create-poll from build-time ISR to a runtime API route with short CDN stale-while-revalidate caching, so newly proposed LIPs appear after a reload without waiting for a redeploy.

Changes:

  • Added GET /api/polls/lips that assembles eligible LIPs at request time with cache headers.
  • Refactored /voting/create-poll to fetch LIPs via SWR and display loading/error states.
  • Extracted LIP/poll filtering logic into lib/api/poll-lips.ts with shared response types.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
pages/voting/create-poll.tsx Switches LIP loading to SWR and adds loading/error UI; updates selection/link logic.
pages/api/polls/lips.ts New API route serving eligible LIPs with cache headers.
lib/api/types/get-poll-lips.ts Adds shared types for the LIPs API payload.
lib/api/poll-lips.ts Implements runtime aggregation/filtering of eligible LIPs from GitHub + subgraph/IPFS.

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

Comment thread pages/voting/create-poll.tsx
Comment thread pages/voting/create-poll.tsx Outdated
Comment thread lib/api/poll-lips.ts
Comment thread lib/api/poll-lips.ts
Comment thread pages/voting/create-poll.tsx Outdated
@ECWireless ECWireless changed the title 562 lips do not immediately appear in create a poll fix: change create a poll LIP fetch to cached runtime API call Jun 28, 2026
@ECWireless ECWireless requested a review from rickstaa June 28, 2026 00:32
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.

LIPs do not immediately appear in Create a Poll

2 participants