-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: inertnal fix screenshot dom display bug #82
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes involve the removal of the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (2)
packages/docs/fluent-editor/demos/screenshot.vue (1)
Remaining References to
imgToBase64
FoundThe
imgToBase64
function still exists and is being used in the following files:
packages/fluent-editor/src/utils/image.ts
packages/fluent-editor/src/screenshot/index.ts
Please ensure that all usages of
imgToBase64
are addressed accordingly.🔗 Analysis chain
Line range hint
1-35
: Clarify the removal of theimgToBase64
functionThe
imgToBase64
function has been removed from this file. While this might be related to fixing the screenshot display bug, I have a few questions:
- Is the functionality of converting images to base64 no longer required for the screenshot feature or anywhere else in the application?
- If it's still needed, how is this conversion being handled now?
- If it's no longer needed, could you please add a comment explaining why this functionality was removed? This would help future maintainers understand the reasoning behind this change.
Let's check if there are any remaining references to
imgToBase64
in the codebase:This will help us ensure that all references to this function have been properly removed or updated.
Adjusting the search command to correctly include
.vue
filesThe previous search command failed to recognize the
vue
file type. Please run the following script to search for any remaining references toimgToBase64
in.vue
,.ts
, and.js
files:[/run_scripts]
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining references to imgToBase64 rg 'imgToBase64' --type vue --type typescript --type javascriptLength of output: 103
Script:
#!/bin/bash # Search for any remaining references to imgToBase64 in .vue, .ts, and .js files rg 'imgToBase64' -g '*.vue' -g '*.ts' -g '*.js'Length of output: 366
packages/fluent-editor/src/screenshot/index.ts (1)
78-78
: Correct typo in comment for clarityThere's a typo in the comment on line 78: "transform will be settle". Consider changing it to "transform will be set" or "transform will be applied" for clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- packages/docs/fluent-editor/demos/screenshot-upload-to-server.vue (0 hunks)
- packages/docs/fluent-editor/demos/screenshot.vue (1 hunks)
- packages/fluent-editor/src/screenshot/index.ts (3 hunks)
- packages/fluent-editor/src/utils/image.ts (1 hunks)
💤 Files not reviewed due to no reviewable changes (1)
- packages/docs/fluent-editor/demos/screenshot-upload-to-server.vue
🔇 Additional comments not posted (5)
packages/fluent-editor/src/utils/image.ts (4)
1-1
: LGTM: Function signature is well-defined.The function signature is clear, descriptive, and properly typed. The use of a Promise for this asynchronous operation is appropriate.
17-20
: LGTM: Error handling is appropriate.The error handling for image loading failures is well implemented. The error message is clear and includes the problematic URL, which will be helpful for debugging.
1-20
: Please clarify how this function addresses the PR objectives.While the
imgToBase64
function is well-implemented, it's not immediately clear how it relates to the "screenshot dom display bug" mentioned in the PR objectives. Could you provide more context on how this utility function helps resolve the issue?To find related changes or usage of this function, run:
#!/bin/bash # Search for files that import or use the imgToBase64 function rg --type typescript -e 'import.*imgToBase64' -e 'imgToBase64\('This will help understand the broader context of the changes and how they relate to the PR objectives.
2-5
: 🛠️ Refactor suggestionConsider security implications and add input validation.
The use of
crossOrigin = 'Anonymous'
allows loading images from different origins, which is flexible but may have security implications. Additionally, consider adding input validation for theimageUrl
parameter.To check if this function is used with user-provided URLs, run:
Consider adding URL validation:
if (!imageUrl || !/^https?:\/\/.+/.test(imageUrl)) { return Promise.reject(new Error('Invalid image URL')); }packages/docs/fluent-editor/demos/screenshot.vue (1)
Line range hint
1-35
: Summary of changes and potential impactThe changes in this file primarily involve simplifying the screenshot configuration and removing custom image processing logic. While these changes appear to address the screenshot display bug mentioned in the PR objectives, there are a few points to consider:
- The removal of custom behavior in the screenshot configuration might affect how screenshots are captured and processed.
- The elimination of the
imgToBase64
function suggests a change in how images are handled during the screenshot process.These changes could potentially impact the overall functionality of the screenshot feature. It's crucial to ensure that:
- The screenshot feature still works as expected after these simplifications.
- Any dependent code that might have relied on the removed functionality has been updated accordingly.
- The changes are well-documented, especially if they represent a significant shift in how the screenshot feature operates.
To get a broader view of the impact, let's check for any other files that might be affected by these changes:
#!/bin/bash # Search for files that mention 'screenshot' in the context of the editor rg 'screenshot.*editor' --type vue --type typescript --type javascript -lThis will help us identify any other files that might need to be updated or reviewed in light of these changes.
* fix: focus call scrollIntoView effect screenshot position * fix: scroll bar hide effect page width
@zzxming 需要解决下冲突哈 |
@zzxming 好像现在截图不准确了,不知道是不是和合入 #81 这个PR有关 |
…ming/fluent-editor into feat-screenshot-operate-node
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (4)
packages/fluent-editor/src/assets/fullscreen.scss (1)
17-20
: Approved addition of.scroll__wrap
with a suggestion.The
.scroll__wrap
class creates a scrollable container that takes up the full height of its parent, which is a good approach for managing overflow content.Consider adding
width: 100%;
to ensure the container also takes up the full width of its parent, which is often desirable for scrollable containers:.scroll { &__wrap { overflow: auto; height: 100%; + width: 100%; } }
packages/fluent-editor/src/utils/scroll-lock.ts (2)
2-25
: Approved with minor suggestions for improvementThe
getScrollBarWidth
function is well-implemented, using an efficient caching mechanism and a common technique for measuring scrollbar width. However, consider the following improvements:
- Add error handling for cases where the target element doesn't exist.
- Use more specific class names for temporary elements to avoid potential conflicts.
Here's a suggested implementation with these improvements:
let scrollBarWidth: number export const getScrollBarWidth = ({ target = document.body } = {}): number => { if (scrollBarWidth !== undefined) return scrollBarWidth if (!target) throw new Error('Target element not found') const outer = document.createElement('div') outer.className = 'fluent-editor__scrollbar-measure-outer' outer.style.visibility = 'hidden' outer.style.width = '100px' outer.style.position = 'absolute' outer.style.top = '-9999px' target.appendChild(outer) const widthNoScroll = outer.offsetWidth outer.style.overflow = 'scroll' const inner = document.createElement('div') inner.className = 'fluent-editor__scrollbar-measure-inner' inner.style.width = '100%' outer.appendChild(inner) const widthWithScroll = inner.offsetWidth outer.parentNode?.removeChild(outer) scrollBarWidth = widthNoScroll - widthWithScroll return scrollBarWidth }
27-52
: Approved with suggestions for improvementThe
lockScroll
function is well-implemented, providing a mechanism to lock scrolling and adjust for the scrollbar width. However, consider the following improvements:
- Add error handling for cases where the target element doesn't exist.
- Use a more specific class name to avoid potential conflicts.
- Make the cleanup function more robust.
- Address the static analysis hint about assignment in expressions.
Here's a suggested implementation with these improvements:
const LOCK_CLASS = 'fluent-editor__scroll-lock' export const lockScroll = ({ target = document.body } = {}) => { if (!target) throw new Error('Target element not found') let scrollBarWidth = 0 let originWidth = target.style.width const hasLockClass = target.classList.contains(LOCK_CLASS) if (hasLockClass) return () => {} // Already locked, return no-op cleanup scrollBarWidth = getScrollBarWidth({ target }) const hasOverflow = (target === document.body ? document.documentElement : target).clientHeight < target.scrollHeight const overflowY = window.getComputedStyle(target).overflowY if (scrollBarWidth > 0 && (hasOverflow || overflowY === 'scroll')) { target.style.width = `calc(100% - ${scrollBarWidth}px)` } target.classList.add(LOCK_CLASS) return () => { if (target.classList.contains(LOCK_CLASS)) { target.style.width = originWidth target.classList.remove(LOCK_CLASS) } } }This implementation addresses the static analysis hint by avoiding assignment in the cleanup function's expression. It also includes other suggested improvements.
🧰 Tools
🪛 Biome
[error] 34-34: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
packages/fluent-editor/src/screenshot/index.ts (1)
69-101
: Improved handling of fixed/sticky elements and images.The new
onclone
callback effectively addresses the positioning of fixed and sticky elements in screenshots and ensures proper encoding of images. These changes should significantly improve the accuracy of the screenshot output.However, the suggestion to use
getComputedStyle
for more reliable style detection has not been implemented. Consider incorporating this change for even more accurate results.Apply this diff to use
getComputedStyle
:- if (dom.style.top !== 'auto') { + if (getComputedStyle(dom).top !== 'auto') { y = window.scrollY } - if (dom.style.left !== 'auto') { + if (getComputedStyle(dom).left !== 'auto') { x = window.scrollX }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (8)
- .prettierignore (0 hunks)
- .prettierrc (0 hunks)
- .vscode/settings.json (1 hunks)
- packages/fluent-editor/package.json (2 hunks)
- packages/fluent-editor/src/assets/fullscreen.scss (1 hunks)
- packages/fluent-editor/src/screenshot/index.ts (5 hunks)
- packages/fluent-editor/src/toolbar/index.ts (1 hunks)
- packages/fluent-editor/src/utils/scroll-lock.ts (1 hunks)
💤 Files not reviewed due to no reviewable changes (2)
- .prettierignore
- .prettierrc
🧰 Additional context used
🪛 Biome
packages/fluent-editor/src/utils/scroll-lock.ts
[error] 34-34: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
🔇 Additional comments (14)
packages/fluent-editor/src/assets/fullscreen.scss (4)
2-2
: Improved code formatting for fullscreen selectors.The indentation of the
background-color
property has been standardized across all fullscreen selectors, enhancing code readability and maintaining consistent formatting.Also applies to: 5-5, 8-8, 11-11
13-21
: Excellent use of SCSS nesting and BEM naming convention.The structure of the new
.scroll
class and its nested classes demonstrates good use of SCSS features and follows the BEM (Block Element Modifier) naming convention. This approach enhances code readability, maintainability, and scalability.
14-16
: Consider the use of!important
in.scroll--lock
.The
.scroll--lock
class usesoverflow: hidden !important;
which will forcefully prevent scrolling. While this achieves the desired effect, the use of!important
can make styles harder to maintain and override in the future.Consider if
!important
is absolutely necessary here. If it is, please add a comment explaining why. To check for potential conflicts, let's run:#!/bin/bash # Description: Check for other overflow styles that might conflict # Search for other overflow styles rg --type css 'overflow:' -C 2
13-13
: New.scroll
class added.A new
.scroll
class has been introduced, which appears to be a container for scroll-related styles.Could you please provide documentation or comments explaining the purpose and usage of this new class? This will help maintain clear understanding for future developers.
To verify the usage of this class, let's run the following script:
.vscode/settings.json (2)
3-3
:⚠️ Potential issueClarify the rationale for disabling Prettier
The addition of
"prettier.enable": false
raises some concerns:
- This change disables Prettier in VS Code, which could lead to inconsistent code formatting across the project.
- It doesn't seem to align with the PR's stated objective of fixing a screenshot DOM display bug.
- It might conflict with the project's coding standards or CI/CD pipeline.
Could you please clarify:
- Why is Prettier being disabled?
- How does this relate to the screenshot DOM display bug mentioned in the PR description?
- Is this change intended to be temporary or permanent?
- Have you confirmed that this won't cause issues with the project's coding standards or CI/CD pipeline?
To ensure this change doesn't conflict with project standards, let's check for Prettier configuration:
Line range hint
1-18
: Consider reviewing ESLint configuration for potential improvementsWhile the ESLint configuration looks generally good, there are a few points to consider:
With Prettier disabled and both ESLint and editor formatting enabled, there might be potential conflicts. Have you tested to ensure these settings work well together?
The
"eslint.useFlatConfig": false
setting indicates that the project is not using the new ESLint flat config format. Is there a plan to migrate to the flat config in the future for improved performance and flexibility?The ESLint validation includes JavaScript, TypeScript, and Vue files. Is this comprehensive for your project, or are there any other file types that should be included?
Consider reviewing these settings to ensure they align with the project's long-term goals and best practices.
Let's check the ESLint configuration to ensure it aligns with these VS Code settings:
✅ Verification successful
ESLint Configuration Alignment Verified
The ESLint configuration in
.eslintrc.js
aligns with the.vscode/settings.json
settings. With Prettier disabled and ESLint handling formatting, there should be no conflicts. The ESLint rules are comprehensive for JavaScript, TypeScript, and Vue files.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check ESLint configuration echo "ESLint configuration:" fd -e js -e cjs -e json --exec grep -l 'eslintConfig' {}Length of output: 111
Script:
#!/bin/bash # Search for ESLint configuration files echo "Searching for ESLint configuration files:" fd -e js -e mjs -e cjs -e json -e yaml -e yml -e js -e ts '^\.eslintrc(\.js|\.json|\.yaml|\.yml)?$' .Length of output: 404
Script:
#!/bin/bash # Search for ESLint configuration files including hidden files echo "Searching for ESLint configuration files (including hidden files):" fd -H -e js -e mjs -e cjs -e json -e yaml -e yml -e ts '^\.eslintrc(\.js|\.json|\.yaml|\.yml)?$' .Length of output: 258
Script:
#!/bin/bash # Display the contents of the ESLint configuration file echo "Contents of .eslintrc.js:" cat ./.eslintrc.jsLength of output: 1914
packages/fluent-editor/package.json (3)
39-39
: LGTM: Test script is correctly configured.The test script is properly set up to use Jest for running tests, which is a standard and recommended practice.
Line range hint
1-62
: LGTM: Overall package.json structure is well-maintained.The package.json file maintains a consistent and standard structure, including all necessary fields such as name, version, description, scripts, and dependencies. The file appears to be well-organized and follows best practices for npm package configuration.
Line range hint
1-62
: Verify removal of 'format' script and 'prettier' dependency.The AI summary indicates that the 'format' script and 'prettier' dependency have been removed, but these changes are not visible in the provided code snippet. If this is correct, it could impact the project's code formatting workflow.
Please run the following script to verify these changes:
If these changes are confirmed:
- How will code formatting be handled going forward?
- Is there a project-wide decision to remove Prettier, or is this specific to the fluent-editor package?
- Have all team members been informed about this change in the development workflow?
✅ Verification successful
Confirmation of Removal of 'format' Script and 'prettier' Dependency
The removal of the 'format' script and 'prettier' dependency in
packages/fluent-editor/package.json
has been confirmed. This change will impact the project's code formatting workflow.Please consider addressing the following:
- How will code formatting be handled going forward?
- Is there a project-wide decision to remove Prettier, or is this specific to the fluent-editor package?
- Have all team members been informed about this change in the development workflow?
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the removal of 'format' script and 'prettier' dependency # Test 1: Check for 'format' script echo "Checking for 'format' script:" jq '.scripts.format' packages/fluent-editor/package.json # Test 2: Check for 'prettier' in devDependencies echo "Checking for 'prettier' in devDependencies:" jq '.devDependencies.prettier' packages/fluent-editor/package.json # Expected results: # If both commands return 'null', it confirms the removal of the 'format' script and 'prettier' dependency.Length of output: 311
packages/fluent-editor/src/toolbar/index.ts (1)
143-143
: Approve the focus method modification for screenshot functionality.The change to prevent scrolling when focusing for the 'screenshot' format looks good. This should address the screenshot DOM display bug mentioned in the PR objectives.
To ensure the fix works as intended, please verify the following:
- The screenshot functionality works correctly without unexpected scrolling.
- Other toolbar actions are not affected by this change.
- The user experience for taking screenshots is improved.
Consider adding a test case to cover this scenario if not already present.
packages/fluent-editor/src/screenshot/index.ts (4)
5-6
: LGTM: New imports for enhanced functionality.The addition of
imgToBase64
andlockScroll
imports suggests improved image processing and scroll management, which aligns well with the screenshot feature enhancements.
55-59
: Skipping comment on potential null reference error.A previous review has already addressed the potential null reference error in the
findParentFixed
function. Please refer to the existing comment for the suggested fix.
144-144
: LGTM: Improved scroll management during screenshot process.The addition of
lockScroll
and its cleanup calls effectively prevents unwanted scrolling during the screenshot process, enhancing the user experience. The placement ofcleanLock()
calls ensures proper cleanup in various scenarios.Also applies to: 149-149, 157-157
Line range hint
1-238
: Summary of changes and suggestionsThe changes in this file effectively address the screenshot DOM display bug by:
- Improving the handling of fixed and sticky positioned elements.
- Ensuring proper encoding of images in the screenshot.
- Implementing scroll locking during the screenshot process.
These enhancements should significantly improve the accuracy and user experience of the screenshot feature. Consider implementing the suggested use of
getComputedStyle
for even more reliable style detection.Overall, the changes align well with the PR objectives and represent a solid improvement to the screenshot functionality.
🧰 Tools
🪛 Biome
[error] 66-67: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes
Chores