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

breaking: remove double navigation, debounce navigate after timeout #60

Merged
merged 3 commits into from
Dec 20, 2023

Conversation

paoloricciuti
Copy link
Owner

@paoloricciuti paoloricciuti commented Dec 18, 2023

Also feat: add showDefaults option to avoid redirecting in case the search param is not present

Summary by CodeRabbit

  • New Features

    • Introduced a new showDefaults option to control the visibility of default parameter values in the URL.
    • Enhanced query parameter handling with debouncing capabilities.
  • Enhancements

    • Improved the display and management of query parameters in the user interface.
  • Documentation

    • Updated README with information about the new showDefaults option.
  • Tests

    • Expanded test coverage to include new functionality and ensure proper behavior of the showDefaults feature.
    • Refined test descriptions and assertions for better clarity and accuracy.

feat: add showDefaults option to chose wether to show the defaults or not in the URL
Copy link

changeset-bot bot commented Dec 18, 2023

🦋 Changeset detected

Latest commit: 9af4ffb

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 Major

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 Dec 18, 2023

Walkthrough

The project introduced a showDefaults option to manage the visibility of default query parameters in URLs. It also enhanced the handling of query parameters with debouncing in the Svelte playground, refining user interactions. The sveltekit-search-params library saw updates to support these features, including new types and store functionality. Tests were expanded to cover the new features, ensuring default values are correctly handled and URL updates occur as expected.

Changes

File Path Change Summary
README.md Added showDefaults option for controlling the display of default URL values.
.../debounce/+page.svelte
.../default/+page.svelte
Introduced debouncing for query parameter changes and modified query parameter display with additional parameters.
src/lib/sveltekit-search-params.ts Added showDefaults to StoreOptions, new Overrides<T> type, and updated functions for new features.
tests/index.test.ts Updated and added tests for showDefaults behavior, URL update timing, and query parameter functionality.

🐇✨
A little rabbit hopped along,
Tweaking URLs, making them strong.
With a debounce in its step,
Defaults hide, or show with pep! 🎉

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for sveltekit-search-params ready!

Name Link
🔨 Latest commit 9af4ffb
🔍 Latest deploy log https://app.netlify.com/sites/sveltekit-search-params/deploys/6581518cca656500087446a1
😎 Deploy Preview https://deploy-preview-60--sveltekit-search-params.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 75ba336 and 2e5c91a.
Files selected for processing (6)
  • .changeset/kind-horses-melt.md (1 hunks)
  • README.md (1 hunks)
  • playground/src/routes/debounce/+page.svelte (1 hunks)
  • playground/src/routes/default/+page.svelte (1 hunks)
  • src/lib/sveltekit-search-params.ts (8 hunks)
  • tests/index.test.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • .changeset/kind-horses-melt.md
Additional comments: 17
README.md (1)
  • 398-422: The documentation for the showDefaults option is clear and provides useful examples for its implementation. This aligns with the PR's objectives to manage the display of default values in the URL.
playground/src/routes/debounce/+page.svelte (1)
  • 9-9: The str2 parameter is initially set as a boolean, but later it is assigned a string value. Ensure that this is the intended behavior and that the parameter type is handled correctly throughout the application.
playground/src/routes/default/+page.svelte (3)
  • 5-7: The str_no_show parameter is correctly configured to not show its default value in the URL.

  • 11-16: The store_no_show object is correctly set up to handle the str2-no-show parameter with the showDefaults option set to false.

  • 2-27: Ensure that the rest of the application correctly handles the absence of str-no-show and str2-no-show from the URL when their values are set to defaults.

src/lib/sveltekit-search-params.ts (9)
  • 37-40: The addition of showDefaults to StoreOptions aligns with the PR objectives to control the visibility of default values in the URL.

  • 53-59: The introduction of Overrides<T> type and its parameter in mixSearchAndOptions function is a good approach to allow specific overrides to the default behavior.

  • 73-75: The logic to apply overrides in mixSearchAndOptions is correctly checking for undefined values before applying them.

  • 168-175: The queryParameters function has been updated to include showDefaults in StoreOptions and to support debouncing. Ensure that the debouncing mechanism works as intended and that the showDefaults option behaves correctly.

  • 213-259: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [180-231]

Verify that the changeImmediately parameter is always defined when calling _set within queryParameters. If it's not defined, it could lead to unexpected behavior.

  • 237-251: The derived store in queryParameters correctly uses the mixSearchAndOptions function and applies the showDefaults logic. Ensure that the showDefaults option behaves as expected when default parameters are present.

  • 270-278: The queryParam function has been updated to include showDefaults in StoreOptions and to support debouncing. Ensure that the debouncing mechanism works as intended and that the showDefaults option behaves correctly.

  • 304-353: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [282-322]

Verify that the changeImmediately parameter is always defined when calling _set within queryParam. If it's not defined, it could lead to unexpected behavior.

  • 329-350: The derived store in queryParam correctly uses the mixSearchAndOptions function and applies the showDefaults logic. Ensure that the showDefaults option behaves as expected when default parameters are present.
tests/index.test.ts (3)
  • 320-385: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [311-335]

The test case correctly checks for the absence of parameters when showDefaults is false, ensuring that the URL is clean of default parameters that are not supposed to be shown. This aligns with the PR objective to introduce the showDefaults option.

  • 338-382: The test case for the debounce functionality seems to be well-implemented. It waits for the debounce timeout before checking the URL parameters, which ensures that the navigation function is debounced as intended. This aligns with the PR objective to implement a debounce mechanism for navigation.

  • 391-394: The test case for default values during server-side rendering (SSR) checks that the values are present even when JavaScript is disabled. This ensures that the default values are handled correctly in SSR scenarios.

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 2e5c91a and 8b31648.
Files selected for processing (1)
  • tests/index.test.ts (7 hunks)
Additional comments: 6
tests/index.test.ts (6)
  • 87-87: The addition of an assertion to check the text content of an element after a change is a good practice to ensure that the UI reflects the state correctly.

  • 144-152: The tests have been updated to check the text content of elements after changes, which is good for verifying that the UI updates as expected.

  • 243-243: Again, the added assertion is good for ensuring that the UI reflects the state correctly after changes.

  • 300-308: The tests have been updated to check the text content of elements after changes, which is good for verifying that the UI updates as expected.

  • 328-393: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [319-390]

The new tests for the debounce functionality and the handling of default values are comprehensive and ensure that the new features work as expected. It's important to verify that the URL is updated correctly after the debounce timeout and that default values are handled correctly in the URL.

  • 399-402: The test for default values during server-side rendering (SSR) is important to ensure that the application behaves correctly when JavaScript is disabled. This test verifies that default values are still present even without client-side navigation.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8b31648 and 9af4ffb.
Files selected for processing (1)
  • src/lib/sveltekit-search-params.ts (8 hunks)
Additional comments: 12
src/lib/sveltekit-search-params.ts (12)
  • 6-12: The import of Svelte store functions and types is correctly done, ensuring that the necessary tools for state management are available.

  • 40-40: The addition of the showDefaults property to the StoreOptions type aligns with the PR objective to control the display of default values in the URL.

  • 53-55: The new Overrides<T> type is introduced correctly, allowing for optional overriding of specific properties in an object of type T.

  • 59-59: The addition of the overrides parameter to the mixSearchAndOptions function is consistent with the new Overrides<T> type, but ensure that all calls to this function are updated to include this new parameter.

Verification successful

The previous script failed because the rg command did not recognize the typescript file type. To ensure that we search all relevant files, we can omit the file type and search across all files. Let's try running the search again without specifying the file type.


The output indicates that there is only one call to mixSearchAndOptions within the src/lib/sveltekit-search-params.ts file. However, the output does not show the full context of the call, specifically whether the new overrides parameter is being passed.

To verify if the overrides parameter is included in the call to mixSearchAndOptions, we need to inspect the arguments passed to the function in the provided line of code. Let's write a script to extract a few lines around the call to mixSearchAndOptions to see the actual parameters being passed.


The provided output shows the context around the call to mixSearchAndOptions within the src/lib/sveltekit-search-params.ts file. It confirms that the function is called with three arguments: $page?.url?.searchParams, $overrides, and options. This indicates that the new overrides parameter has been correctly included in the call to mixSearchAndOptions.

Based on this information, the addition of the overrides parameter to the mixSearchAndOptions function has been properly handled in the call within the src/lib/sveltekit-search-params.ts file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to mixSearchAndOptions to ensure they include the new overrides parameter.
rg --type typescript "mixSearchAndOptions\("

Length of output: 81



Script:

#!/bin/bash
# Search for calls to mixSearchAndOptions to ensure they include the new overrides parameter.
rg "mixSearchAndOptions\("

Length of output: 126



Script:

#!/bin/bash
# Extract the context around the call to mixSearchAndOptions to check the passed parameters
rg -C 3 "mixSearchAndOptions\(" src/lib/sveltekit-search-params.ts

Length of output: 273

* 170-175: The `queryParameters` function now includes the `showDefaults` property in its options, which is in line with the PR objectives. However, the default value for `showDefaults` is set to `true`, which may change the current behavior for consumers not expecting this new feature. Ensure that this change is communicated and documented.
  • 177-177: The creation of a writable store for overrides is appropriate for managing state overrides in a reactive manner.

  • 216-226: The navigate function within queryParameters is correctly using the sort and pushHistory options to control the URL navigation behavior. However, ensure that the overrides.set({}) call is intended to reset the overrides after navigation, as this could lead to unexpected behavior if overrides are meant to persist.

  • 240-247: The derived store setup is correct, and the use of mixSearchAndOptions within it is appropriate. The conditional check for anyDefaultedParam && showDefaults ensures that defaults are only set when specified, which is a good implementation of the new feature.

  • 276-281: The queryParam function has been updated to include the showDefaults property, which is consistent with the changes made to queryParameters. Ensure that the default behavior change is documented.

  • 283-283: The creation of a writable store for override in queryParam is consistent with the approach taken in queryParameters.

  • 310-320: The navigate function within queryParam is using the sort and pushHistory options correctly. The reset of the override store after navigation is a potential point of confusion and should be verified for intended behavior.

  • 335-343: The derived store in queryParam is set up correctly, with proper handling of the showDefaults option. The conditional logic to set the default value only when showDefaults is true is a good implementation detail.

src/lib/sveltekit-search-params.ts Show resolved Hide resolved
@paoloricciuti paoloricciuti merged commit ac8263b into master Dec 20, 2023
5 checks passed
@github-actions github-actions bot mentioned this pull request Dec 20, 2023
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.

1 participant