Skip to content

Switch to polar astro package#3361

Merged
RobbieTheWagner merged 3 commits intomainfrom
polar-astro
Feb 12, 2026
Merged

Switch to polar astro package#3361
RobbieTheWagner merged 3 commits intomainfrom
polar-astro

Conversation

@RobbieTheWagner
Copy link
Member

@RobbieTheWagner RobbieTheWagner commented Feb 12, 2026

Summary by CodeRabbit

  • Refactor

    • Checkout flow moved from client-side actions to a server-side endpoint; pricing buttons now navigate to that endpoint.
    • Button behavior updated to show loading state, disable during checkout, and restore state on return/navigation.
  • Chores

    • Dependency updated to a renamed package to align with current platform packaging.

@vercel
Copy link

vercel bot commented Feb 12, 2026

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

Project Deployment Actions Updated (UTC)
shepherd-docs Ready Ready Preview, Comment Feb 12, 2026 4:38pm
shepherd-landing Ready Ready Preview, Comment Feb 12, 2026 4:38pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

Migrates checkout from client-side Astro actions to a server-side API route, swaps the Polar dependency from @polar-sh/sdk to @polar-sh/astro, removes the exported server.checkout action, adds /api/checkout GET handler, and updates the pricing page to navigate to the API endpoint.

Changes

Cohort / File(s) Summary
Dependency Update
landing/package.json
Replaced @polar-sh/sdk with @polar-sh/astro and updated version from ^0.20.2 to ^0.7.3.
Removed Action
landing/src/actions/index.ts
Deleted the exported server.checkout action and all related Polar client initialization, checkout creation, error handling, and URL-return logic.
API Route Added
landing/src/pages/api/checkout.ts
New API route: prerender = false and GET exported via `Checkout({ accessToken: process.env.POLAR_ACCESS_TOKEN
Pricing Page Changes
landing/src/pages/pricing.astro
Replaced astro:actions flow with full-page navigation to /api/checkout?products=<productId>, updated data-pricing-id values, added button disable/loading state and restoration handlers (visibilitychange/pageshow), removed client-side Polar action usage.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant PricingPage as Pricing Page
    participant APIRoute as /api/checkout
    participant Polar as Polar Service

    User->>PricingPage: Click pricing button
    PricingPage->>PricingPage: disable button, show loading
    PricingPage->>APIRoute: Navigate to /api/checkout?products=<productId>
    APIRoute->>Polar: Create checkout session (productId, successUrl)
    Polar-->>APIRoute: Return checkout URL
    APIRoute-->>User: Redirect to returned checkout URL
    PricingPage->>PricingPage: on visibility/pageshow restore button state
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped from client to server tonight,
A little route born to make checkout right.
Buttons freeze, then dart to a Polar URL,
I nibble code crumbs and give a soft twirl.
Hooray for tidy hops and smoother flight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: migrating from @polar-sh/sdk to @polar-sh/astro package while restructuring the checkout implementation accordingly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch polar-astro

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
landing/src/pages/pricing.astro (2)

366-377: Event listeners accumulate on repeated page visits.

visibilitychange and pageshow listeners are registered inside astro:page-load but never removed. With Astro View Transitions, astro:page-load fires on every client-side navigation to this page, so each visit adds duplicate listeners. Consider using astro:after-swap for cleanup, or use { once: true } where appropriate, or register these listeners outside the astro:page-load callback.

Proposed fix using AbortController for cleanup
  document.addEventListener('astro:page-load', () => {
+   const controller = new AbortController();
+   const signal = controller.signal;
+
+   // Clean up listeners on next page swap
+   document.addEventListener('astro:before-swap', () => controller.abort(), { once: true });
+
    const buttons = document.querySelectorAll('[data-pricing-id]');
    // ...

    // Listen for page visibility changes (when user comes back from checkout)
-   document.addEventListener('visibilitychange', () => {
+   document.addEventListener('visibilitychange', () => {
      if (document.visibilityState === 'visible') {
        resetButtons();
      }
-   });
+   }, { signal });

    // Also reset on page show event (handles browser back button)
-   window.addEventListener('pageshow', (event) => {
+   window.addEventListener('pageshow', (event) => {
      resetButtons();
-   });
+   }, { signal });

398-398: Use btn instead of event.target for consistency.

btn is already assigned from event.target on line 384 after the type guard. Using event.target?.dataset.pricingId here is redundant optional chaining and inconsistent with the rest of the handler.

Proposed fix
-        const productId = event.target?.dataset.pricingId;
+        const productId = btn.dataset.pricingId;

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.

@qltysh
Copy link

qltysh bot commented Feb 12, 2026

Qlty

Coverage Impact

This PR will not change total coverage.

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

Copy link

@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: 2

🤖 Fix all issues with AI agents
In `@landing/package.json`:
- Line 16: package.json lists a non-existent "@polar-sh/astro" version "0.7.3"
which breaks npm install and the Checkout import in
landing/src/pages/api/checkout.ts; update the dependency entry for
"@polar-sh/astro" to a valid published version such as "^0.4.6" (or the latest
available) so the package resolves correctly and the Checkout import can be
found during build.

In `@landing/src/pages/pricing.astro`:
- Around line 376-377: The client-side call using navigate() to hit the server
endpoint /api/checkout with products=${productId} should be replaced with a
full-page browser navigation so the server-side redirect to Polar's external
checkout can be followed; locate the call to navigate(...) (using the productId
variable) in pricing.astro and replace it with a standard browser navigation
method (e.g., window.location.href or location.assign) so the request performs a
full-page load and the server redirect is honored.
🧹 Nitpick comments (3)
landing/src/pages/api/checkout.ts (1)

5-8: Silent fallback to empty access token could cause confusing runtime errors.

If POLAR_ACCESS_TOKEN is unset, the empty-string fallback will let the request reach Polar's API, which will likely reject it with an opaque auth error. Consider failing fast at startup or at least logging a clear message.

Proposed improvement
+const accessToken = import.meta.env.POLAR_ACCESS_TOKEN;
+if (!accessToken) {
+  throw new Error('POLAR_ACCESS_TOKEN environment variable is not set');
+}
+
 export const GET = Checkout({
-  accessToken: import.meta.env.POLAR_ACCESS_TOKEN ?? '',
+  accessToken,
   successUrl: 'https://docs.shepherdjs.dev'
 });
landing/src/pages/pricing.astro (2)

366-366: Use btn instead of re-reading event.target.

btn was already assigned from event.target at line 352 after the instanceof guard. Using btn.dataset.pricingId is cleaner and avoids the unnecessary optional chaining.

Proposed fix
-        const productId = event.target?.dataset.pricingId;
+        const productId = btn.dataset.pricingId;

56-56: Product IDs are hardcoded in the template.

These UUIDs will need to change per environment (staging vs. production). Consider sourcing them from environment variables or a config to avoid code changes when IDs rotate.

Also applies to: 143-143

"@astrojs/mdx": "^4.3.13",
"@astrojs/vercel": "^9.0.2",
"@polar-sh/sdk": "^0.20.2",
"@polar-sh/astro": "^0.7.3",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

@polar-sh/astro npm package version 0.7.3

💡 Result:

@polar-sh/astro does not have an npm release 0.7.3. The npm package page shows @polar-sh/astro at 0.4.6 (latest) and indicates its published versions are in the 0.4.x line, not 0.7.x. [1]

If you were trying to install a Polar adapter at 0.7.3, that version does exist for @polar-sh/sveltekit (Polar’s SvelteKit adapter), which is listed as 0.7.3. [2]

Polar’s Astro adapter docs show the package name to install is @polar-sh/astro. [3]

Sources: [1] [2] [3]


🏁 Script executed:

# Check if checkout.ts file exists and examine Checkout usage
find . -name "checkout.ts" -path "*/landing/src/pages/api/*" -type f

Repository: shipshapecode/shepherd

Length of output: 101


🏁 Script executed:

# Look at the package.json structure to understand context
cat -n landing/package.json | head -30

Repository: shipshapecode/shepherd

Length of output: 1011


🏁 Script executed:

# Examine the checkout.ts file to see what is imported
cat -n landing/src/pages/api/checkout.ts

Repository: shipshapecode/shepherd

Length of output: 334


Update @polar-sh/astro to a valid version.

@polar-sh/astro v0.7.3 does not exist on npm. The latest available version is 0.4.6. Update the dependency to a valid version (e.g., "^0.4.6"), otherwise npm install will fail and Checkout import in landing/src/pages/api/checkout.ts will not resolve.

🤖 Prompt for AI Agents
In `@landing/package.json` at line 16, package.json lists a non-existent
"@polar-sh/astro" version "0.7.3" which breaks npm install and the Checkout
import in landing/src/pages/api/checkout.ts; update the dependency entry for
"@polar-sh/astro" to a valid published version such as "^0.4.6" (or the latest
available) so the package resolves correctly and the Checkout import can be
found during build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant