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

Replace query-string dependency with URLSearchParams #336

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

askoufis
Copy link
Contributor

@askoufis askoufis commented Mar 2, 2024

The platform-native URLSearchParams has broad browser support, so we don't really have a need for query-string anymore.

@askoufis askoufis requested a review from a team as a code owner March 2, 2024 10:03
Copy link

changeset-bot bot commented Mar 2, 2024

🦋 Changeset detected

Latest commit: 6cbbc72

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

This PR includes changesets to release 1 package
Name Type
playroom 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

Comment on lines -22 to +30
const { themeName, code } = useParams((rawParams) => ({
themeName:
typeof rawParams.themeName === 'string' ? rawParams.themeName : '',
code: typeof rawParams.code === 'string' ? rawParams.code : '',
}));
const { themeName, code } = useParams((rawParams) => {
const rawThemeName = rawParams.get('themeName');
const rawCode = rawParams.get('code');

return {
themeName: rawThemeName || '',
code: rawCode || '',
};
});
Copy link
Contributor Author

@askoufis askoufis Mar 2, 2024

Choose a reason for hiding this comment

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

query-string's API returned a single value or an array, but URLSearchParams' .get API returns string | null, so there's no need for a typeof check here anymore.

Copy link
Member

@jahredhope jahredhope left a comment

Choose a reason for hiding this comment

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

But what about my 8 year old Samsung phone that I refuse to update since I first bought it?

Comment on lines 23 to +30
try {
return queryString.parse(
return new URLSearchParams(
playroomConfig.paramType === 'hash'
? location.hash.replace(/^#/, '')
: location.search
);
} catch (err) {
return {};
return new URLSearchParams();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This try catch might not even be needed anymore since AFAICT URLSearchParams constructor never throws. I couldn't make it throw on any input, and a cursory glance at the spec didn't mention throwing. But probably better to be safe than sorry.

@askoufis askoufis enabled auto-merge (squash) March 4, 2024 23:53
@askoufis askoufis merged commit 0215bb4 into master Mar 5, 2024
6 checks passed
@askoufis askoufis deleted the remove-query-string branch March 5, 2024 00:02
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