Skip to content

Update Modal component to Svelte 5#820

Merged
chrisvire merged 5 commits into
sillsdev:mainfrom
judah-sotomayor:update/Modal
Jun 5, 2025
Merged

Update Modal component to Svelte 5#820
chrisvire merged 5 commits into
sillsdev:mainfrom
judah-sotomayor:update/Modal

Conversation

@judah-sotomayor

@judah-sotomayor judah-sotomayor commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

Per #819

Tested on all locations where Modal is used:

  • PlanStopDialog
  • NoteDialog
  • AudioPlaybackSpeed
  • TextAppearanceSelector
  • CollectionSelector
  • FontSelector

Label functionality is currently untested.
Not sure how to test that.

Summary by CodeRabbit

  • Refactor
    • Updated modal components to use a new syntax for content rendering, replacing slot fragments with snippet blocks.
    • Removed the label trigger from modal dialogs for a cleaner interface.
    • Streamlined modal content rendering and event handling for a more consistent user experience.

Switch Svelte 4 `export let` statements to Svelte 5
`let {...} = $props();`

Replace all fragment calls inside Modal elements by snippets.
Convert `on:click` to Svelte 5 `onclick`.
Convert `on:close` to Svelte 5 `onclose`.
Add `onclose` to props list, fixing NotesDialog.
Fix issue where label snippet is not rendered.
@coderabbitai

coderabbitai Bot commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change updates how modal content is defined and rendered across several Svelte components. The approach shifts from using named slot fragments (<svelte:fragment slot="content">) and the useLabel prop to a function-prop-driven pattern using snippet blocks ({#snippet content()}) and direct function invocation for content and label rendering in the Modal component.

Changes

File(s) Change Summary
src/lib/components/Modal.svelte Refactored to use destructured $props(), removed useLabel, switched to function-prop-driven content rendering, replaced slot rendering with direct snippet rendering, removed label slot and button, and updated event bindings. Retained exported showModal() function.
src/lib/components/AudioPlaybackSpeed.svelte
src/lib/components/CollectionSelector.svelte
src/lib/components/FontSelector.svelte
src/lib/components/NoteDialog.svelte
src/lib/components/PlanStopDialog.svelte
src/lib/components/TextAppearanceSelector.svelte
Updated modal usage: removed useLabel={false}, replaced <svelte:fragment slot="content"> with {#snippet content()} for modal content injection, and changed event binding syntax from on:close to onclose where applicable.

Sequence Diagram(s)

sequenceDiagram
    participant ParentComponent as Any Component (e.g., AudioPlaybackSpeed)
    participant Modal as Modal.svelte

    ParentComponent->>Modal: Pass props (id, content, label, addCSS, onclose)
    Modal->>Modal: Render label if label() exists (removed in this update)
    Modal->>Modal: Render content via content() function
    Modal->>ParentComponent: Call onclose() when modal closes
Loading

Possibly related PRs

  • Fix issues with playback speed #816: Modifies AudioPlaybackSpeed.svelte to add dynamic speed options, programmatic modal control, and fixes playback speed modal invocation and styling, directly related due to overlapping component and modal usage changes.

Poem

A modal’s tale, now told anew,
With snippets neat and props in view.
No slots to name, no labels forced,
Just functions called and flows endorsed.
The dialog opens, clean and bright,
Svelte rabbits hop with code delight! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-05T19_42_12_881Z-debug-0.log


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c73c0cd and 2fb4792.

📒 Files selected for processing (1)
  • src/lib/components/Modal.svelte (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/components/Modal.svelte
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint
  • GitHub Check: test

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
🪧 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.

@judah-sotomayor judah-sotomayor changed the title Update Modal component to Svelte 5 per #819 Update Modal component to Svelte 5 Jun 5, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/lib/components/NoteDialog.svelte (1)

56-97: 💡 Verification agent

🧩 Analysis chain

LGTM! Complete Svelte 5 Modal migration with proper event handling.

This file demonstrates the full migration pattern:

  • Correct snippet syntax replacing slots
  • Proper event handling update from on:close={reset} to onclose={reset} prop
  • All conditional content and editing functionality preserved

The migration to Svelte 5 patterns is correctly implemented.

Since this is a breaking API change affecting the Modal component, please verify that all Modal component usages across the codebase have been updated to the new Svelte 5 pattern:


🏁 Script executed:

#!/bin/bash
# Description: Verify all Modal component usages have been updated to Svelte 5 patterns
# Expected: No old slot-based patterns should remain

echo "=== Checking for old slot-based Modal patterns ==="
rg -A 3 -B 1 '<svelte:fragment slot="content">' 

echo "=== Checking for old useLabel prop usage ==="
rg -A 2 -B 1 'useLabel='

echo "=== Checking for old on:close event handlers on Modal ==="
rg -A 2 -B 1 'on:close.*=' --type svelte

echo "=== Verifying all Modal usages now use snippet pattern ==="
rg -A 5 '<Modal' | rg -A 5 '\{#snippet'

Length of output: 4956


Incomplete Svelte 5 Modal migration: remaining old slot-based patterns

The verification script shows several components still using the legacy <svelte:fragment slot="content"> API. Please update these to the new {#snippet content()} pattern and remove any old slot-based Modal props:

• src/lib/components/ChapterSelector.svelte
• src/lib/components/LayoutOptions.svelte (two occurrences)
• src/lib/components/BookSelector.svelte

Additionally, ensure none of these files use the old on:close={…} event syntax—replace with the Svelte 5 onclose={…} prop.

🧹 Nitpick comments (1)
src/lib/components/Modal.svelte (1)

15-15: Consider adding prop validation for better developer experience.

While the current implementation works, consider adding runtime validation to ensure content and label are functions when provided, especially since this is a breaking API change.

 let { id, addCSS = '', content, label, onclose } = $props();
+
+// Validate function props
+if (content && typeof content !== 'function') {
+    console.warn('Modal: content prop must be a snippet function');
+}
+if (label && typeof label !== 'function') {
+    console.warn('Modal: label prop must be a snippet function');
+}

Also applies to: 40-40

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61435f7 and 4981c82.

📒 Files selected for processing (7)
  • src/lib/components/AudioPlaybackSpeed.svelte (2 hunks)
  • src/lib/components/CollectionSelector.svelte (2 hunks)
  • src/lib/components/FontSelector.svelte (2 hunks)
  • src/lib/components/Modal.svelte (2 hunks)
  • src/lib/components/NoteDialog.svelte (2 hunks)
  • src/lib/components/PlanStopDialog.svelte (2 hunks)
  • src/lib/components/TextAppearanceSelector.svelte (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: lint
🔇 Additional comments (12)
src/lib/components/PlanStopDialog.svelte (1)

44-68: LGTM! Correct Svelte 5 Modal migration.

The migration from slot-based content (<svelte:fragment slot="content">) to snippet-based content ({#snippet content()}) follows the correct Svelte 5 pattern. The modal content and functionality are preserved unchanged.

src/lib/components/FontSelector.svelte (1)

27-43: LGTM! Consistent Svelte 5 Modal migration.

The migration correctly updates the Modal usage to Svelte 5 snippet syntax while preserving all existing functionality including the FontList component and action buttons.

src/lib/components/CollectionSelector.svelte (1)

66-106: LGTM! Proper Svelte 5 migration with complex content preserved.

The migration correctly implements the snippet-based approach while maintaining the complex TabsMenu structure and layout options. All functionality appears to be preserved in the transition to Svelte 5.

src/lib/components/AudioPlaybackSpeed.svelte (2)

32-32: LGTM: Modal component migration looks correct.

The removal of useLabel={false} prop aligns with the new Modal API where label rendering is conditional based on the presence of the label prop.


33-56: LGTM: Snippet syntax correctly implemented.

The migration from <svelte:fragment slot="content"> to {#snippet content()} is properly implemented and follows Svelte 5 conventions.

src/lib/components/TextAppearanceSelector.svelte (2)

108-108: LGTM: Modal props correctly updated.

The removal of useLabel={false} and preservation of addCSS prop is correct for the new Modal API.


109-200: LGTM: Snippet migration properly implemented.

The content has been correctly wrapped in a {#snippet content()} block, maintaining all the existing functionality while adopting Svelte 5 conventions.

src/lib/components/Modal.svelte (5)

6-11: LGTM: Prop documentation correctly updated.

The prop documentation accurately reflects the new API with function-based content and label props.


15-15: LGTM: Props destructuring correctly implemented.

The use of $props() with destructuring and default values follows Svelte 5 conventions properly.


19-25: LGTM: Exported showModal function properly implemented.

This provides programmatic control over the modal, which is essential for the component's functionality.


40-40: LGTM: Event binding correctly updated for Svelte 5.

The direct {onclose} prop binding is the correct approach for Svelte 5 event handling.


49-49: LGTM: Snippet rendering correctly implemented.

The use of {@render content?.()} with optional chaining is a good defensive programming practice.

Comment thread src/lib/components/Modal.svelte Outdated
Make `label` and `onclose` default to `null`.
@chrisvire

chrisvire commented Jun 5, 2025

Copy link
Copy Markdown
Member

I believe I recently removed the last place where "useLabel" was used (it caused problems and was not useful). I will remove it.

@chrisvire

Copy link
Copy Markdown
Member

A better branch name would have been feature/migrate-modal

* The last use of the label was removed in PR#816. Realistically, it was
  a bad idea.

@chrisvire chrisvire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

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