Skip to content

feat(core,vue): Improve anchor position behavior - #2

Merged
stefashkaa merged 12 commits into
mainfrom
feat/improve-position-anchor
Aug 7, 2026
Merged

feat(core,vue): Improve anchor position behavior#2
stefashkaa merged 12 commits into
mainfrom
feat/improve-position-anchor

Conversation

@stefashkaa

@stefashkaa stefashkaa commented Aug 5, 2026

Copy link
Copy Markdown
Member

Description

  • What does this PR do?

    • Improves anchored panel positioning in the core widget and Vue component
    • Prefers opening above the trigger, flips below when necessary, and chooses the roomier side when neither can fit the requested height
    • Constrains the panel to the visible viewport, including mobile browser and on-screen-keyboard changes
    • Repositions on viewport, trigger, and panel size changes, with animation direction matching placement
    • Updates documentation, unit coverage, the demo bundle, and the runtime bundle-size budget
  • Why is this change needed?

    • Anchored panels could overlap their trigger or extend beyond the visible viewport as the viewport, trigger, or panel changed. This was particularly noticeable on mobile devices when browser chrome or the on-screen keyboard shifted the visual viewport

Type of Change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change
  • Documentation update
  • Tests
  • Maintenance

Testing

  • pnpm test:unit
  • pnpm test:e2e

Screenshots (if applicable)

  • N/A, covered by layout and runtime unit tests

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex code
  • Documentation updated
  • No new warnings generated
  • Tests added/updated
  • All tests passing

Run Coverage Workflow

Maintainers only (write/maintain/admin access): open the workflow, click Run workflow, and set pr_number to this PR number to post/update a coverage comment on this PR

Summary by CodeRabbit

  • New Features

    • Anchor-positioned panels now open above triggers by default and intelligently flip or choose the roomier side.
    • Panels stay within visible viewport boundaries, including mobile keyboard viewports.
    • Configurable maximum width, height, and vertical transition offsets are supported.
  • Bug Fixes

    • Panel positions now update reliably after scrolling, resizing, viewport changes, and content size changes.
    • Improved positioning near viewport edges and shifted mobile viewports.

Copilot AI lite review requested due to automatic review settings August 5, 2026 12:42
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
context7-widget Ready Ready Preview Aug 7, 2026 1:08am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f4647f31-3524-4ba4-9689-955ff470d813

📥 Commits

Reviewing files that changed from the base of the PR and between 8b4f00b and 495b6c5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • common/styles/_widget.scss
  • common/tests/unit/dom.ts
  • demo/package.json
  • demo/public/widget.js
  • package.json
  • packages/core/README.md
  • packages/core/src/dom.ts
  • packages/core/src/index.ts
  • packages/core/src/kit.ts
  • packages/core/src/widget-element.ts
  • packages/core/tests/unit/dom.test.ts
  • packages/core/tests/unit/widget-element.test.ts
  • packages/vue/package.json
  • packages/vue/src/components/Context7Widget.vue
  • packages/vue/tests/unit/context7-widget.test.ts
  • pnpm-workspace.yaml
  • scripts/check-bundle-size.mts

📝 Walkthrough

Walkthrough

Changes

Anchor positioning now prefers the top side, flips or selects the roomier side when needed, and constrains panel dimensions to the visible viewport. Core, custom-element, Vue, and demo implementations respond to viewport and element changes through scheduled updates. Tests, styles, documentation, exports, and bundle limits were updated.

Anchor positioning

Layer / File(s) Summary
Layout resolution contract
packages/core/src/dom.ts, packages/core/src/index.ts, packages/core/src/kit.ts, packages/core/tests/unit/layout.test.ts, packages/core/tests/unit/dom.test.ts, common/tests/unit/dom.ts, packages/core/README.md
The shared layout API now returns placement and maximum dimensions. It uses viewport offsets, margins, available space, and document-dimension fallbacks.
Custom-element viewport updates
packages/core/src/widget-element.ts, common/styles/_widget.scss, packages/core/tests/unit/widget-element.test.ts
The custom element observes viewport and element changes, coalesces updates through render frames, applies placement and maximum-size variables, and cleans up resources.
Vue and demo integration
packages/vue/src/components/Context7Widget.vue, packages/vue/tests/unit/context7-widget.test.ts, demo/public/widget.js, docs/INTEGRATION.md
Vue and demo positioning use the shared layout helper. They respond to viewport and resize changes and apply placement-dependent styles.
Validation and distribution updates
scripts/check-bundle-size.mts, package.json, demo/package.json, packages/vue/package.json, pnpm-workspace.yaml
Bundle budgets and dependency ranges were updated for the new implementation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Context7Widget
  participant VisualViewport
  participant ResizeObserver
  participant AnchorPanel
  User->>Context7Widget: open anchored widget
  Context7Widget->>VisualViewport: read dimensions and offsets
  Context7Widget->>ResizeObserver: observe anchor and panel
  Context7Widget->>AnchorPanel: apply position, maximum dimensions, and translation
  VisualViewport->>Context7Widget: resize or scroll event
  ResizeObserver->>Context7Widget: geometry change
  Context7Widget->>AnchorPanel: reposition on next render frame
Loading

Poem

A rabbit checks the viewport wide,
Then sets the panel’s top-side stride.
If space is tight, it flips below,
With bounded width and height in tow.
Resize and scroll call frames to run—
Cleanup hops when work is done.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: improved anchor positioning behavior in the core and Vue components.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/improve-position-anchor

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

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@packages/core/src/widget-element.ts`:
- Around line 705-707: Replace the nullish coalescing operators with
positive-value fallback checks in the viewportWidth and viewportHeight chains of
packages/core/src/widget-element.ts (lines 705-707) and
packages/vue/src/components/Context7Widget.vue (lines 736-737), allowing zero
window dimensions to fall through to document dimensions and panel dimensions.
Regenerate packages/demo/public/widget.js at line 131 from the corrected
sources; do not edit the minified bundle manually.
🪄 Autofix

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 326586fa-7092-486e-97e3-afe6642adb7c

📥 Commits

Reviewing files that changed from the base of the PR and between b2e23ec and 8b4f00b.

📒 Files selected for processing (10)
  • common/styles/_widget.scss
  • demo/public/widget.js
  • docs/INTEGRATION.md
  • packages/core/src/dom.ts
  • packages/core/src/widget-element.ts
  • packages/core/tests/unit/layout.test.ts
  • packages/core/tests/unit/widget-element.test.ts
  • packages/vue/src/components/Context7Widget.vue
  • packages/vue/tests/unit/context7-widget.test.ts
  • scripts/check-bundle-size.mts

Comment thread packages/core/src/widget-element.ts Outdated

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.

🔵 Human review recommended

The changes alter cross-browser UI layout behavior across core, Vue, styles, and bundled artifacts and should be manually validated in real browsers/devices.

Pull request overview

This PR improves the widget’s position="anchor" behavior across the core custom element and the Vue wrapper by making placement smarter (prefer above, flip below, pick roomier side), constraining size to the visual viewport (including mobile chrome/keyboard effects), and re-positioning reliably as viewport/anchor/panel dimensions change.

Changes:

  • Update the anchor layout resolver to account for visualViewport offsets and return maxHeight/maxWidth + placement metadata.
  • Add throttled re-positioning for anchored panels using requestAnimationFrame, visualViewport events, and ResizeObserver (core + Vue).
  • Update styling/tests/docs and refresh demo/runtime artifacts, including a bundle size budget adjustment.
File summaries
File Description
scripts/check-bundle-size.mts Updates the gzip budget for the core runtime consumer to reflect the new logic.
packages/vue/tests/unit/context7-widget.test.ts Adds unit coverage for visual viewport + ResizeObserver-driven anchor updates in Vue.
packages/vue/src/components/Context7Widget.vue Implements throttled anchor re-positioning and visual viewport / ResizeObserver tracking.
packages/core/tests/unit/widget-element.test.ts Updates anchor tests for async scheduling and adds visual viewport / ResizeObserver coverage.
packages/core/tests/unit/layout.test.ts Expands layout unit tests for new placement/max sizing and visual viewport offsets.
packages/core/src/widget-element.ts Adds throttled repositioning, visual viewport listeners, and ResizeObserver support for anchored widgets.
packages/core/src/dom.ts Enhances resolveContext7AnchorLayout to produce max constraints and support visual viewport offsets.
docs/INTEGRATION.md Documents the updated anchor placement and visual viewport-constrained behavior.
demo/public/widget.js Refreshes the demo bundle to include new anchor behavior and CSS variables.
common/styles/_widget.scss Uses new CSS variables to constrain anchor max-size and match animation direction to placement.
Review details

Files not reviewed (1)

  • demo/public/widget.js: Generated file
  • Files reviewed: 9/10 changed files
  • Comments generated: 0
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

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.

🟡 Changes recommended

The new anchor transition CSS uses a --c7-anchor-translate-y fallback that conflicts with the default preferred placement, causing incorrect initial open animation direction.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Files not reviewed (1)

  • demo/public/widget.js: Generated file

Suppressed comments (2)

common/styles/_widget.scss:1030

  • Same issue as the desktop anchor panel styles: the mobile anchor panel uses a -8px fallback for --c7-anchor-translate-y, which conflicts with the default preferred top placement (should start from +8px unless overridden by JS).
      transform: translateY(var(--c7-anchor-translate-y, -8px)) scale(0.98);

common/styles/_widget.scss:575

  • The fallback for --c7-anchor-translate-y is -8px, but the anchor layout now prefers opening above the trigger (placement top), where the code sets --c7-anchor-translate-y to 8px. On first open (before JS sets the variable), this causes the entry transition to animate from the wrong direction.

This issue also appears on line 1030 of the same file.

    transform: translateY(var(--c7-anchor-translate-y, -8px)) scale(0.98);
  • Files reviewed: 9/10 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@socket-security

Copy link
Copy Markdown

@socket-security

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm jsdom is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: package.jsonnpm/jsdom@30.0.1

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/jsdom@30.0.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

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

Copilot reviewed 18 out of 20 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • demo/public/widget.js: Generated file

@stefashkaa
stefashkaa merged commit 11afdc6 into main Aug 7, 2026
7 checks passed
@stefashkaa
stefashkaa deleted the feat/improve-position-anchor branch August 7, 2026 11:39
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