8000 fix(compat): fix compat handler of draggable by yangxiuxiu1115 · Pull Request #12445 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

fix(compat): fix compat handler of draggable #12445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yangxiuxiu1115
Copy link
Contributor
@yangxiuxiu1115 yangxiuxiu1115 commented Nov 20, 2024

fix #12444
image

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of enumerated attributes to ensure values like null, false, or the string 'false' are correctly coerced and rendered as expected.
  • Tests

    • Added a new test case to verify correct behavior and deprecation warning when the compatibility flag for enumerated attribute coercion is enabled.

Copy link
github-actions bot commented Nov 20, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.3 kB 34.5 kB
vue.global.prod.js 159 kB 58.5 kB 52 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.8 kB 23 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.6 kB 26.4 kB 24 kB

Copy link
pkg-pr-new bot commented Nov 20, 2024

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@12445

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@12445

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@12445

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@12445

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@12445

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@12445

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@12445

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@12445

@vue/shared

npm i https://pkg.pr.new/@vue/shared@12445

vue

npm i https://pkg.pr.new/vue@12445

@vue/compat

npm i https://pkg.pr.new/@vue/compat@12445

commit: 5e0e684

@yangxiuxiu1115 yangxiuxiu1115 marked this pull request as draft November 20, 2024 10:27
@yangxiuxiu1115 yangxiuxiu1115 marked this pull request as ready for review November 20, 2024 11:42
@edison1105 edison1105 added 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: v2 compat labels Nov 21, 2024
@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor
vue-bot commented Nov 21, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools success success
nuxt success success
pinia success success
primevue success success
quasar success success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros success success
vuetify success success
vueuse success success
vue-simple-compiler success success

@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Nov 21, 2024
@@ -500,3 +500,11 @@ test('local app config should not affect other local apps in v3 mode', () => {
const app2 = createApp({})
expect(app2.config.globalProperties.test).toBe(undefined)
})

test('ATTR_ENUMERATED_COERCION: true', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether the tests for this should be in misc.spec.ts instead, as there are already tests for ATTR_ENUMERATED_COERCION in that file?

Comment on lines 62 to 64
value === null || value === false || value === 'false'
? 'false'
: typeof value !== 'boolean' && value !== undefined
: value !== undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the logic is correct, but it might be easier to understand if the undefined check were handled first?

Copy link
coderabbitai bot commented May 27, 2025

Walkthrough

The internal logic for coercing enumerated attribute values in the compatCoerceAttr function was updated to correctly handle string values like 'false'. A new test was added to verify that, with the compatibility flag enabled, attributes such as draggable="false" are rendered as expected and the appropriate warning is issued.

Changes

File(s) Change Summary
packages/runtime-dom/src/modules/attrs.ts Revised compatCoerceAttr logic to treat null, false, and 'false' as 'false', else 'true'.
packages/vue-compat/tests/misc.spec.ts Added test for ATTR_ENUMERATED_COERCION with draggable="false" and deprecation warning check.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant VueInstance
    participant compatCoerceAttr
    participant DOM

    TestRunner->>VueInstance: Mount with compatConfig ATTR_ENUMERATED_COERCION: true
    VueInstance->>compatCoerceAttr: Coerce 'draggable' attribute with value 'false'
    compatCoerceAttr-->>VueInstance: Return 'false'
    VueInstance->>DOM: Render <div draggable="false">
    VueInstance->>TestRunner: Emit deprecation warning
    TestRunner->>TestRunner: Assert rendered HTML and warning
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure draggable="false" is preserved as draggable="false" with ATTR_ENUMERATED_COERCION (12444)

Poem

A bunny hopped through code so neat,
Fixing "draggable" with nimble feet.
Now "false" stays false, no more a ruse,
With tests to prove the bug's defuse.
The carrot of truth in every line—
Compatibility, now working fine! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (1)
packages/vue-compat/__tests__/misc.spec.ts (1)

287-289: Note: Pre-existing type annotation pattern (not blocking).

The static analysis tool flags the use of Function as a type, suggesting to explicitly define the function shape. However, this pattern is used consistently throughout the file (lines 262, 268, 274, etc.), so this is a pre-existing codebase pattern rather than an issue introduced by this change.

🧰 Tools
🪛 Biome (1.9.4)

[error] 288-288: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a58947 and 5e0e684.

📒 Files selected for processing (2)
  • packages/runtime-dom/src/modules/attrs.ts (1 hunks)
  • packages/vue-compat/__tests__/misc.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/runtime-dom/src/modules/attrs.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/vue-compat/__tests__/misc.spec.ts

[error] 288-288: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / e2e-test
  • GitHub Check: test / unit-test-windows
🔇 Additional comments (1)
packages/vue-compat/__tests__/misc.spec.ts (1)

279-291: LGTM! Good test coverage for the compatibility flag.

The new test case effectively verifies that when ATTR_ENUMERATED_COERCION is explicitly enabled, the draggable="false" attribute is preserved correctly and the appropriate deprecation warning is emitted. This complements the existing test and follows the established testing patterns in the file.

🧰 Tools
🪛 Biome (1.9.4)

[error] 288-288: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

Copy link
Contributor
@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

A few more thoughts on the test...


test('ATTR_ENUMERATED_COERCION: true', () => {
const vm = new Vue({
compatConfig: { ATTR_ENUMERATED_COERCION: true },
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? I think this is enabled in this file by default.

@@ -275,3 +275,17 @@ test('ATTR_ENUMERATED_COERCION', () => {
)('contenteditable', 'foo', 'true'),
).toHaveBeenWarned()
})

test('ATTR_ENUMERATED_COERCION: true', () => {
8000
Copy link
Contributor

Choose a reason for hiding this comment

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

The test name should be more specific. Something like:

Suggested change
test('ATTR_ENUMERATED_COERCION: true', () => {
test('ATTR_ENUMERATED_COERCION, coercing "false"', () => {

test('ATTR_ENUMERATED_COERCION: true', () => {
const vm = new Vue({
compatConfig: { ATTR_ENUMERATED_COERCION: true },
template: `<div><div draggable="false">hello</div></div>`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also test boolean false. e.g.:

Suggested change
template: `<div><div draggable="false">hello</div></div>`,
template: `<div><div draggable="false" :spellcheck="false">hello</div></div>`,

Plus the relevant assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: v2 compat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ATTR_ENUMERATED_COERCION coerces draggable="false" to draggable="true"
4 participants
0