Skip to content

replace deriveAsync and deriveAsyncIfDefined with runed resource#1695

Merged
hahn-kev merged 2 commits into
developfrom
fix-derive-async
May 27, 2025
Merged

replace deriveAsync and deriveAsyncIfDefined with runed resource#1695
hahn-kev merged 2 commits into
developfrom
fix-derive-async

Conversation

@hahn-kev

Copy link
Copy Markdown
Collaborator

closes #980

I also did a bit of refactoring to simplify our related project handling

@coderabbitai

coderabbitai Bot commented May 22, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes remove the custom asynchronous debouncing utilities (deriveAsync, makeDebouncer) and their tests, shifting reactive state management in Svelte components to use the runed library's $state and resource constructs. Related code and template bindings are updated accordingly. Additional input validation is added to project query functions.

Changes

Files/Paths Change Summary
frontend/src/lib/util/time.ts, frontend/src/lib/util/time.test.ts Removed all custom debouncing utilities (deriveAsync, makeDebouncer) and related unit tests. Only basic timing utilities remain.
frontend/src/lib/forms/UserTypeahead.svelte Refactored from Svelte store-based state management to use runed's $state and resource for reactive state and async fetching.
frontend/src/routes/(authenticated)/project/create/+page.svelte Replaced multiple Svelte derived stores with runed resources and watch utilities for code availability and related projects lookup.
frontend/src/routes/(authenticated)/project/create/+page.ts Added input validation guards to prevent unnecessary GraphQL queries for invalid project code or name lengths.

Assessment against linked issues

Objective Addressed Explanation
Remove or fix deriveAsync so its debouncing behavior matches its documentation (#980)

Poem

A bunny hopped through fields of code,
Swapping stores for runed—what a load!
Debouncers gone, async made neat,
With cleaner checks, the code’s a treat.
No more confusion, just swift delight—
The carrot of progress tastes just right! 🥕


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.

@github-actions

github-actions Bot commented May 22, 2025

Copy link
Copy Markdown
Contributor

UI unit Tests

10 tests   10 ✅  0s ⏱️
 3 suites   0 💤
 1 files     0 ❌

Results for commit c3e641f.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented May 22, 2025

Copy link
Copy Markdown
Contributor

C# Unit Tests

116 tests  ±0   116 ✅ ±0   10s ⏱️ ±0s
 17 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit c3e641f. ± Comparison against base commit 7040f15.

♻️ This comment has been updated with latest results.

@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

🧹 Nitpick comments (5)
frontend/src/lib/forms/UserTypeahead.svelte (2)

42-44: Add explicit generic to resource for safer typings

runed will infer any[] for the resource unless a generic is supplied. Supplying the expected element type improves IntelliSense and prevents silent type regressions.

-const _typeaheadResults = resource(() => trigger, (value) => typeaheadSearch(value), {initialValue: [], debounce: debounceMs});
+const _typeaheadResults = resource<UserTypeaheadResult[]>(
+  () => trigger,
+  (value) => typeaheadSearch(value),
+  { initialValue: [], debounce: debounceMs }
+);

132-133: Confirm onInput payload is always a string

PlainInput sometimes forwards the original InputEvent. If that happens, value ?? '' will yield '[object InputEvent]' rather than the empty string, re-triggering the search with garbage.
Please ensure PlainInput’s onInput always supplies a string, or narrow the type here:

-onInput={(value) => trigger = value ?? ''}
+onInput={(v) => trigger = typeof v === 'string' ? v : ''}
frontend/src/routes/(authenticated)/project/create/+page.ts (1)

109-113: Guard clause still allows 1-character language codes

_getProjectsByLangCodeAndOrg only short-circuits for lengths other than 2 or 3, meaning a single-character langCode proceeds to the network call.
That is unlikely to be valid and wastes a request. Consider extending the guard:

-if (input.langCode.length !== 3 && input.langCode.length !== 2) return [];
+if (input.langCode.length !== 2 && input.langCode.length !== 3) return [];

(also trims whitespace to avoid " " being considered 1 char).

frontend/src/routes/(authenticated)/project/create/+page.svelte (2)

105-112: Avoid network hit while user is still typing very short codes

The availability check fires as soon as code.length >= 1.
You already know codes shorter than 4 fail validation, so you can skip the fetch entirely and save server load:

-  if (!browser || !code || !user.canCreateProjects || code === defaultCode) return true;
+  if (!browser || !code || code.length < 4 || !user.canCreateProjects || code === defaultCode)
+    return true;

186-193: Watcher mutates form on every keystroke – consider batching

watch(() => code, …) writes back into the form on each character, marking it dirty and potentially triggering expensive validations.
Debounce or batch the update to improve responsiveness for very long inputs.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7040f15 and c49ab90.

📒 Files selected for processing (5)
  • frontend/src/lib/forms/UserTypeahead.svelte (4 hunks)
  • frontend/src/lib/util/time.test.ts (0 hunks)
  • frontend/src/lib/util/time.ts (0 hunks)
  • frontend/src/routes/(authenticated)/project/create/+page.svelte (6 hunks)
  • frontend/src/routes/(authenticated)/project/create/+page.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • frontend/src/lib/util/time.test.ts
  • frontend/src/lib/util/time.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build API / publish-api
  • GitHub Check: Build UI / publish-ui
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: check-and-lint
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (2)
frontend/src/lib/forms/UserTypeahead.svelte (1)

48-50: Race-condition risk when calling onSelectedUserChange

selectUser sets selectedUser and immediately invokes the callback with that reactive reference.
If the parent mutates selectedUser inside the callback, the assignment order may cause surprising results.
Consider passing an immutable clone, or at minimum dereferencing .value/.current before emitting.

frontend/src/routes/(authenticated)/project/create/+page.ts (1)

128-130: Mirror the min-length check from the Zod schema

projectName.length < 3 aligns with the resource debounce, but the form actually requires min(1).
If you tighten the guard to 3, make sure the schema/UX communicates this to the user to avoid silent “nothing happens” states.

Comment thread frontend/src/routes/(authenticated)/project/create/+page.svelte
@hahn-kev hahn-kev requested a review from rmunn May 22, 2025 03:52
Runed resource requires an async fetcher function, so even when we can
resolve without async we need to return a resolved Promise.

@rmunn rmunn 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.

LGTM. There was a reason why we used deriveAsyncIfDerived at one point, but I think we prevented the possibility of undefined getting returned from those GQL queries, so although we're not replicating the if (value) { ... } behavior of deriveAsyncIfDerived, that's probably okay.

Comment thread frontend/src/lib/forms/UserTypeahead.svelte
@hahn-kev hahn-kev merged commit d6ace5a into develop May 27, 2025
17 checks passed
@hahn-kev hahn-kev deleted the fix-derive-async branch May 27, 2025 09:03
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.

Our deriveAsync function says debounce is optional but it always debounces

3 participants