Skip to content
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

Fix the override setting to allow for false values #74

Merged

Conversation

TravelingTice
Copy link
Contributor

@TravelingTice TravelingTice commented Mar 4, 2024

Hi @paoloricciuti 👋

I found a small bug when using the package with a store value that was a boolean, and by default false. I had this mount on a form submit after which a checkbox component would be mounted, mapped to a queryParam store that was of type boolean and by default false. It caused this weird infinite redirect loop, here is a little video of it:

Screen.Recording.2024-03-04.at.15.47.37.mov

Was able to trace it down to an evaluation of $override which wouldn't work for false values. Changed it to do a comparison of null which should be a bit safer, as the type of this is T | null, so I assume that we want this path to run only when non-null.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the accuracy of query parameter handling by ensuring only non-null values affect the control flow.

Copy link

changeset-bot bot commented Mar 4, 2024

🦋 Changeset detected

Latest commit: a87044a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sveltekit-search-params Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Mar 4, 2024

Walkthrough

The change involves a refinement in the logic for handling query parameters within a specific function. This adjustment shifts the focus from evaluating truthiness to explicitly checking for non-null values, thereby refining the control flow based on more precise value checks. This subtle yet significant change ensures a more accurate handling of query parameters and introduces a new functionality related to allowing false values in sveltekit-search-params.

Changes

File Path Change Summary
src/lib/sveltekit-search-params Modified condition to check for non-null instead of truthy values in query parameter handling. Introduces fix for allowing false values in sveltekit-search-params.

🐰✨
In the realm of code, where logic intertwines,
A rabbit hopped through, refining the lines.
From truthy to non-null, the checks did evolve,
Ensuring query params, mysteries could solve.
🌟📜

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?

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>.
    • Generate unit-tests for this file.
  • 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 generate unit tests for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

netlify bot commented Mar 4, 2024

Deploy Preview for sveltekit-search-params failed.

Name Link
🔨 Latest commit a87044a
🔍 Latest deploy log https://app.netlify.com/sites/sveltekit-search-params/deploys/65e5ef30ce2df700098122aa

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3f21aab and 96ba605.
Files selected for processing (1)
  • src/lib/sveltekit-search-params.ts (1 hunks)
Additional comments: 1
src/lib/sveltekit-search-params.ts (1)
  • 382-382: The change from a truthy check to a non-null check ($override != null) is a critical improvement for handling boolean values correctly, especially for values that default to false. This adjustment ensures that false values are not incorrectly treated as non-existent or undefined, which aligns with the PR's objective to fix the infinite redirect loop issue. By explicitly checking for null, the code now correctly differentiates between false and null values, allowing for the intended behavior when dealing with boolean query parameters.

This change directly addresses the problem described in the PR objectives and is a safer approach given the explicit typing of $override to be either a generic type T or null. It's a good practice to use strict comparisons and checks in JavaScript to avoid unintended type coercions, which can lead to bugs, especially when dealing with values like 0, '', or false that are falsy but valid in certain contexts.

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 96ba605 and 84627c8.
Files selected for processing (1)
  • .changeset/modern-llamas-bow.md (1 hunks)
Additional comments: 2
.changeset/modern-llamas-bow.md (2)
  • 1-3: The metadata specifying a patch version change for sveltekit-search-params is appropriate given the nature of the fix. This aligns well with semantic versioning practices.
  • 5-5: The description clearly and concisely explains the purpose of the change, which is to fix the override setting to allow for false values. This is crucial for understanding the context and impact of the patch.

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>
Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 84627c8 and a87044a.
Files selected for processing (1)
  • src/lib/sveltekit-search-params.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/lib/sveltekit-search-params.ts

@TravelingTice
Copy link
Contributor Author

Hey @paoloricciuti 👋 Just following up here, I processed your suggestion a couple days ago, so should be all good now 🚀

@paoloricciuti
Copy link
Owner

Hey @paoloricciuti 👋 Just following up here, I processed your suggestion a couple days ago, so should be all good now 🚀

Ugh sorry...thanks for pinging me

@paoloricciuti paoloricciuti merged commit ae6c342 into paoloricciuti:master Mar 9, 2024
1 of 5 checks passed
@github-actions github-actions bot mentioned this pull request Mar 9, 2024
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.

None yet

2 participants