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

feat: sorting search params before navigating #56

Merged
merged 4 commits into from
Dec 16, 2023

Conversation

paoloricciuti
Copy link
Owner

@paoloricciuti paoloricciuti commented Dec 15, 2023

Closes #51

This adds sorting before navigating to allow for better cache-ability. This is technically a breaking change (?) but i'm a bit unsure about the consequences that it might have so i might keep it as a minor

Summary by CodeRabbit

  • Documentation

    • Updated the README to reflect changes in the usage of queryParam and queryParameters functions with improved examples.
  • New Features

    • Introduced handling for new query parameter arr_unordered that maintains an unordered list.
    • Added a new unordered_store to manage the state of unordered arrays in the UI.
  • Refactor

    • Enhanced the queryParameters and queryParam functions with a sort option to control the sorting of query parameters.
  • Tests

    • Added tests to ensure the correct default and custom sorting of query parameters.

Copy link

changeset-bot bot commented Dec 15, 2023

🦋 Changeset detected

Latest commit: e907ec2

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 Minor

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 15, 2023

Walkthrough

The recent updates introduce sorting of query parameters to enhance cache hit rates for HTTP requests. By default, parameters are alphabetically sorted, and developers can customize this behavior or opt out entirely. Changes across several files ensure consistent handling of query parameters, including their declaration, storage, and testing.

Changes

File(s) Change Summary
.gitignore Added "test-results" directory to ignore list.
README.md, .../+page.svelte, .../queryparameters/+page.svelte Updated Svelte component code for handling query parameters with sorting and default values.
src/lib/sveltekit-search-params.ts Enhanced StoreOptions interface and functions for conditional sorting of query parameters.
tests/index.test.ts Added and updated test cases to verify alphabetical ordering and custom sorting functionality.

Assessment against linked issues

Objective Addressed Explanation
Sort params in URL to improve browser cache hit rate (#51) The changes ensure that query parameters are sorted to improve the cache hit rate, addressing the issue's requirements effectively.

Poem

To sort or not, a choice to make, 🐰
With parameters in line, a cache hit rate at stake.
A rabbit hops through code with glee,
For URLs aligned, as neat as can be. 🌟

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

@paoloricciuti paoloricciuti marked this pull request as ready for review December 15, 2023 21:50
Copy link

netlify bot commented Dec 15, 2023

Deploy Preview for sveltekit-search-params ready!

Name Link
🔨 Latest commit e907ec2
🔍 Latest deploy log https://app.netlify.com/sites/sveltekit-search-params/deploys/657d6ca28a397200089d6471
😎 Deploy Preview https://deploy-preview-56--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: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between be89f9b and a33ce79.
Files ignored due to filter (1)
  • package.json
Files selected for processing (6)
  • .gitignore (1 hunks)
  • README.md (13 hunks)
  • playground/src/routes/+page.svelte (2 hunks)
  • playground/src/routes/queryparameters/+page.svelte (2 hunks)
  • src/lib/sveltekit-search-params.ts (5 hunks)
  • tests/index.test.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments: 22
README.md (9)
  • 49-51: The import statement for queryParam has been updated to use single quotes, which is a minor stylistic change and aligns with the summary provided.

  • 100-103: The queryParam function now includes an encode and decode option, which is consistent with the PR's objective to allow for custom sorting or disabling the sorting feature.

  • 120-124: The defaultValue option has been added to the queryParam function call, which is a new feature mentioned in the summary. This allows for a default value to be set for a query parameter.

  • 145-145: The use of helper functions for parameter types (ssp.number()) is demonstrated, which improves readability and usability as mentioned in the summary.

  • 160-160: Here, a default value is passed to the helper function, which is a new feature that aligns with the PR's objective to provide more control over query parameters.

  • 175-175: The queryParameters function is used without arguments, which suggests that it will manage all query parameters without sorting, as per the new feature.

  • 226-228: The queryParameters function is now accepting an object that specifies which parameters should be managed, which is consistent with the PR's objective and the summary provided.

  • 310-310: The use of the ssp.boolean(true) helper function is consistent with the PR's objective to provide helper functions for common parameter types.

  • 404-419: The configuration options for queryParam and queryParameters are demonstrated, which includes the new sort option. This aligns with the PR's objective to allow for better cache-ability by sorting query parameters.

playground/src/routes/+page.svelte (2)
  • 9-11: The implementation of the arr_unordered query parameter with the sort option set to false aligns with the PR's objective to introduce unsorted query parameters for better cache-ability.

  • 47-68: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [6-67]

Given the PR's objective and the changes made, it's important to ensure that the new feature is well-documented and that there are comprehensive tests covering the new sorting behavior. The author's concern about the change being potentially breaking should be addressed by thoroughly reviewing the impact on the public API and considering a major version release if necessary.

playground/src/routes/queryparameters/+page.svelte (3)
  • 13-20: The implementation of unordered_store with the sort property set to false correctly aligns with the PR's objective to allow unsorted query parameters. This should enable the arr-unordered parameter to be managed without affecting cache consistency.

  • 58-74: The addition of the button to add items to the arr-unordered array and the UI elements to display it are consistent with the existing pattern of the application. The use of the spread operator to trigger reactivity in Svelte is correct, ensuring the UI updates when the array changes.

  • 9-11: The existing store initialization does not show any changes related to the new sorting feature. It's important to ensure that documentation and examples are updated to guide users on how to use the new sort property with existing stores if this is a breaking change.

src/lib/sveltekit-search-params.ts (6)
  • 30-34: The addition of the sort property to the StoreOptions interface is consistent with the PR's objective to introduce sorting of search parameters. This is a significant change that could impact existing consumers of these functions.

  • 158-161: The queryParameters function has been updated to include the sort property with a default value of true. This ensures that sorting is enabled by default, maintaining backward compatibility for existing consumers who do not specify the sort option.

  • 246-249: The queryParam function has been updated to include the sort property with a default value of true. This change maintains backward compatibility for existing consumers who do not specify the sort option.

  • 196-208: The conditional sorting logic using the sort property before updating the URL and pushing history is implemented correctly and aligns with the PR's objective to improve cache-ability by ensuring consistent order of query parameters.

  • 274-286: The conditional sorting logic in the queryParam function is consistent with the queryParameters function, correctly using the sort property to ensure the order of query parameters before updating the URL and pushing history.

  • 193-211: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-286]

Given the changes to the function signatures and the introduction of a new feature that alters URL generation behavior, this PR introduces breaking changes. It would be prudent to release these changes as a major version update to adhere to semantic versioning principles.

tests/index.test.ts (2)
  • 119-130: The test case 'parameters are kept in alphabetical order by default' correctly checks the URL search string to ensure parameters are sorted alphabetically. This aligns with the PR's objective to improve cache-ability by sorting query parameters.

  • 272-282: The test case 'parameters are kept in alphabetical order by default' in the queryParameters describe block is similar to the one in the queryParam block. It checks the URL search string to ensure parameters are sorted alphabetically. This is consistent with the feature being tested and the PR's objective.

tests/index.test.ts Show resolved Hide resolved
tests/index.test.ts Show resolved Hide resolved
playground/src/routes/+page.svelte Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
paoloricciuti and others added 2 commits December 15, 2023 22:58
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.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 a33ce79 and 1d5e531.
Files selected for processing (1)
  • README.md (13 hunks)
Files skipped from review as they are similar to previous changes (1)
  • README.md

@paoloricciuti paoloricciuti merged commit 7a99cd8 into master Dec 16, 2023
2 of 3 checks passed
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 1d5e531 and e907ec2.
Files selected for processing (2)
  • .changeset/curvy-icons-protect.md (1 hunks)
  • README.md (13 hunks)
Additional comments: 15
README.md (15)
  • 49-51: The import statement and the usage of queryParam are updated to use single quotes, which is a minor stylistic change. This aligns with the PR's objective to standardize the usage examples in the documentation.

  • 67-67: The example correctly demonstrates the usage of queryParam for a single parameter. It's important to note that the PR's objective mentions sorting, but this simple case does not demonstrate the sorting feature.

  • 87-87: The example shows how to update the query parameter by assigning a new value to the store. This is consistent with the library's usage pattern.

  • 101-103: The encode and decode functions are provided to handle the conversion of a number to a string and vice versa. This is a clear example of how to use these functions with queryParam.

  • 121-123: The defaultValue is introduced in the example, which is consistent with the PR's objective to allow setting default values for query parameters.

  • 145-145: This example uses a helper function ssp.number() to simplify the encoding and decoding process. This is a good demonstration of the library's helper functions.

  • 160-160: The example demonstrates how to use a helper function with a default value, which is a new feature mentioned in the PR's objective.

  • 175-175: The queryParameters function is used without any options, which does not showcase the new sorting feature. It would be beneficial to include an example that demonstrates the sorting functionality.

  • 211-211: This example illustrates updating multiple query parameters at once by modifying the store object, which is consistent with the library's intended functionality.

  • 227-227: The example shows how to specify expected query parameters, which is useful for initializing the store with predefined keys.

  • 267-270: The encode and decode functions are used to handle boolean values, with a defaultValue provided. This is a good example of more complex parameter handling.

  • 310-310: Here, the helper function ssp.boolean(true) is used to simplify the encoding and decoding of a boolean value with a default value, which aligns with the PR's objectives.

  • 396-396: The new sort option is introduced in the documentation, explaining its purpose and default behavior. This is a key part of the PR's objective and should be highlighted to inform users of the breaking change.

  • 406-410: The debounceHistory option is documented, which is not directly related to the sorting feature but is important for users to understand how to control the history behavior.

  • 417-417: The pushHistory option is mentioned, which allows users to control whether changes to the store result in new history entries. This is useful information that should be included in the documentation.

Comment on lines +1 to +5
---
"sveltekit-search-params": minor
---

feat: sorting search params before navigating
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the potential impact of the new sorting feature on existing users' workflows, it might be more appropriate to release this change as a major version update, not a minor one, to clearly communicate the breaking nature of the changes. Please consider the implications of this new feature on existing users and the semantic versioning guidelines.

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.

sort params in url to improve browser cache hit rate
1 participant