Skip to content

fix(drawer): [drawer] modify the bugs in the drawer component and provide additional property testing examples#4195

Merged
zzcr merged 1 commit into
opentiny:devfrom
James-9696:fix-drawer-0427
May 11, 2026
Merged

fix(drawer): [drawer] modify the bugs in the drawer component and provide additional property testing examples#4195
zzcr merged 1 commit into
opentiny:devfrom
James-9696:fix-drawer-0427

Conversation

@James-9696

@James-9696 James-9696 commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

…roperty testing examples 不发

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added demo examples showing drawer component with append-to-body functionality.
  • Bug Fixes

    • Fixed unnecessary DOM re-attachment operations when drawer's append-to-body is enabled.
  • Documentation

    • Enhanced documentation with new examples and localized descriptions for the drawer component's append-to-body attribute.
  • Tests

    • Added test suite validating correct DOM placement behavior for drawer's append-to-body feature.

@github-actions github-actions Bot added the bug Something isn't working label Apr 28, 2026
@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Walkthrough

This PR adds a new demo showcasing the drawer's append-to-body functionality, including both Options API and Composition API variants, along with test coverage and updated API documentation. A guard condition is added to prevent redundant DOM re-attachment in the renderless drawer logic.

Changes

Cohort / File(s) Summary
Demo Components
examples/sites/demos/pc/app/drawer/drawer-to-body.vue, examples/sites/demos/pc/app/drawer/drawer-to-body-composition-api.vue
New demo components displaying drawer with append-to-body enabled, showing button-triggered opening/closing behavior.
Documentation & Configuration
examples/sites/demos/pc/app/drawer/webdoc/drawer.js, examples/sites/demos/apis/drawer.js
Adds documentation entry for drawer-to-body demo and updates API prop mapping to reference the new demo.
Testing
examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts
Playwright test validating that drawer with append-to-body correctly renders as a child of document.body.
Core Logic
packages/renderless/src/drawer/index.ts
Adds guard condition to prevent redundant DOM re-attachment when element is already positioned under document.body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

🐰 A drawer that escapes to the body so free,
With demos to show how it ought to be,
No redundant appends shall clutter the way,
Just append-to-body, hooray, hooray! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title mentions 'modify bugs' and 'provide additional property testing examples', which aligns with the core changeset that adds append-to-body demo examples and fixes a redundant appendChild guard in the drawer component.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@James-9696 James-9696 changed the title fix: modify the bugs in the drawer component and provide additional p… fix: modify the bugs in the drawer component and provide additional property testing examples Apr 28, 2026
@James-9696 James-9696 changed the title fix: modify the bugs in the drawer component and provide additional property testing examples fix(drawer): [drawer] modify the bugs in the drawer component and provide additional property testing examples Apr 28, 2026

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts (1)

1-24: ⚠️ Potential issue | 🟠 Major

E2E spec location does not follow the repository path rule.

This test is added under examples/sites/demos/pc/app/drawer/, while the guideline requires examples/sites/demos/<component-name>/.
As per coding guidelines, "E2E tests must be placed in examples/sites/demos/<component-name>/ directory".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts` around lines 1 -
24, The E2E spec drawer-to-body.spec.ts (test.describe '挂载节点' / test '挂载节点') is
placed under the wrong folder; move this spec into the canonical demos directory
for the component (examples/sites/demos/drawer/) so it follows the rule "E2E
tests must be placed in examples/sites/demos/<component-name>/"; after moving,
update any relative imports or test runner references if needed and ensure the
test still imports { test, expect } from '@playwright/test' and locators (demo,
openBtn, drawer) continue to resolve.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts`:
- Around line 14-18: The test calls drawer.evaluate(...) immediately after
clicking and can be flaky because the drawer may not be attached yet; before
calling evaluate on the locator named drawer (created via page.locator('body >
.tiny-drawer')), add an explicit wait such as awaiting
expect(drawer).toHaveCount(1) to ensure the element is present in the DOM, then
proceed to run drawer.evaluate(...) and the expect(isAppendToBody).toBe(true).

---

Outside diff comments:
In `@examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts`:
- Around line 1-24: The E2E spec drawer-to-body.spec.ts (test.describe '挂载节点' /
test '挂载节点') is placed under the wrong folder; move this spec into the canonical
demos directory for the component (examples/sites/demos/drawer/) so it follows
the rule "E2E tests must be placed in examples/sites/demos/<component-name>/";
after moving, update any relative imports or test runner references if needed
and ensure the test still imports { test, expect } from '@playwright/test' and
locators (demo, openBtn, drawer) continue to resolve.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6e2fdfc7-0954-4be9-b654-eddb443949f7

📥 Commits

Reviewing files that changed from the base of the PR and between 2698d3d and c34e092.

📒 Files selected for processing (6)
  • examples/sites/demos/apis/drawer.js
  • examples/sites/demos/pc/app/drawer/drawer-to-body-composition-api.vue
  • examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts
  • examples/sites/demos/pc/app/drawer/drawer-to-body.vue
  • examples/sites/demos/pc/app/drawer/webdoc/drawer.js
  • packages/renderless/src/drawer/index.ts

Comment on lines +14 to +18
const drawer = page.locator('body > .tiny-drawer')

// drawer 被挂载到 document.body 下
const isAppendToBody = await drawer.evaluate((el) => el.parentElement === document.body)
expect(isAppendToBody).toBe(true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check if the file exists and read its content
cat -n examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts

Repository: opentiny/tiny-vue

Length of output: 1004


🏁 Script executed:

# Check if the directory structure complies with E2E test location guidelines
find examples/sites/demos -name "drawer-to-body.spec.ts" -o -name "*drawer*.spec.ts" | head -20

Repository: opentiny/tiny-vue

Length of output: 119


🏁 Script executed:

# List the directory structure for drawer component
ls -la examples/sites/demos/pc/app/drawer/ 2>/dev/null || echo "Directory not found"

Repository: opentiny/tiny-vue

Length of output: 4504


Add an explicit wait assertion before locator.evaluate to prevent test flakiness.

The drawer is appended to body following the click on line 12, but evaluate is called immediately after without waiting for attachment. Use await expect(drawer).toHaveCount(1) to ensure the element is in the DOM before accessing its properties.

Suggested test-hardening diff
     const drawer = page.locator('body > .tiny-drawer')
+    await expect(drawer).toHaveCount(1)

     // drawer 被挂载到 document.body 下
     const isAppendToBody = await drawer.evaluate((el) => el.parentElement === document.body)
     expect(isAppendToBody).toBe(true)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const drawer = page.locator('body > .tiny-drawer')
// drawer 被挂载到 document.body 下
const isAppendToBody = await drawer.evaluate((el) => el.parentElement === document.body)
expect(isAppendToBody).toBe(true)
const drawer = page.locator('body > .tiny-drawer')
await expect(drawer).toHaveCount(1)
// drawer 被挂载到 document.body 下
const isAppendToBody = await drawer.evaluate((el) => el.parentElement === document.body)
expect(isAppendToBody).toBe(true)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/sites/demos/pc/app/drawer/drawer-to-body.spec.ts` around lines 14 -
18, The test calls drawer.evaluate(...) immediately after clicking and can be
flaky because the drawer may not be attached yet; before calling evaluate on the
locator named drawer (created via page.locator('body > .tiny-drawer')), add an
explicit wait such as awaiting expect(drawer).toHaveCount(1) to ensure the
element is present in the DOM, then proceed to run drawer.evaluate(...) and the
expect(isAppendToBody).toBe(true).

@zzcr
zzcr merged commit 8ba8ff5 into opentiny:dev May 11, 2026
12 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants