Skip to content

Commit

Permalink
fix: qs imports and usage in ESM builds (#5850)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir committed Apr 24, 2024
1 parent 8a8f88b commit c2ef59b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 32 deletions.
10 changes: 10 additions & 0 deletions .changeset/rude-suns-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@refinedev/nextjs-router": patch
"@refinedev/react-router-v6": patch
"@refinedev/remix-router": patch
"@refinedev/strapi-v4": patch
---

fix: replace imports of `qs` with default imports

Updated `qs` imports and usage to prevent issues with ESM builds and to ensure correctly importing the module.
8 changes: 4 additions & 4 deletions packages/nextjs-router/src/app/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@refinedev/core";
import { useRouter, usePathname, useSearchParams } from "next/navigation";
import Link from "next/link";
import { parse, stringify } from "qs";
import qs from "qs";
import React, { ComponentProps, useContext } from "react";
import { paramsFromCurrentPath } from "../common/params-from-current-path";
import { convertToNumberIfPossible } from "src/common/convert-to-number-if-possible";
Expand Down Expand Up @@ -46,7 +46,7 @@ export const routerBindings: RouterBindings = {

const urlQuery = {
...(keepQuery
? parse(searchParamsObj.toString(), {
? qs.parse(searchParamsObj.toString(), {
ignoreQueryPrefix: true,
})
: {}),
Expand All @@ -65,7 +65,7 @@ export const routerBindings: RouterBindings = {
const hasUrlQuery = Object.keys(urlQuery).length > 0;

const fullPath = `${urlTo}${
hasUrlQuery ? stringify(urlQuery, stringifyConfig) : ""
hasUrlQuery ? qs.stringify(urlQuery, stringifyConfig) : ""
}${hasUrlHash ? urlHash : ""}`;

if (type === "path") {
Expand Down Expand Up @@ -109,7 +109,7 @@ export const routerBindings: RouterBindings = {

const parsedParams = React.useMemo(() => {
const searchParams = searchParamsObj.toString();
return parse(searchParams, { ignoreQueryPrefix: true });
return qs.parse(searchParams, { ignoreQueryPrefix: true });
}, [searchParamsObj]);

const fn = React.useCallback(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs-router/src/common/parse-table-params.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { parse } from "qs";
import qs from "qs";
import type { ParsedParams } from "@refinedev/core";

const parseTableParams = (search: string) => {
const parsed: ParsedParams = parse(search, { ignoreQueryPrefix: true });
const parsed: ParsedParams = qs.parse(search, { ignoreQueryPrefix: true });

const tableReady = {
...parsed,
Expand Down
10 changes: 5 additions & 5 deletions packages/nextjs-router/src/pages/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@refinedev/core";
import { useRouter } from "next/router";
import Link from "next/link";
import { parse, stringify } from "qs";
import qs from "qs";
import React, { ComponentProps, useContext } from "react";
import { paramsFromCurrentPath } from "../common/params-from-current-path";
import { convertToNumberIfPossible } from "src/common/convert-to-number-if-possible";
Expand Down Expand Up @@ -44,7 +44,7 @@ export const routerBindings: RouterBindings = {

const urlQuery = {
...(keepQuery
? parse(pathname.split("?")[1], {
? qs.parse(pathname.split("?")[1], {
ignoreQueryPrefix: true,
})
: {}),
Expand All @@ -63,7 +63,7 @@ export const routerBindings: RouterBindings = {
const hasUrlQuery = Object.keys(urlQuery).length > 0;

const fullPath = `${urlTo}${
hasUrlQuery ? stringify(urlQuery, stringifyConfig) : ""
hasUrlQuery ? qs.stringify(urlQuery, stringifyConfig) : ""
}${hasUrlHash ? urlHash : ""}`;

if (type === "path") {
Expand Down Expand Up @@ -109,11 +109,11 @@ export const routerBindings: RouterBindings = {

const parsedParams = React.useMemo(() => {
const searchParams = pathname.split("?")[1];
return parse(searchParams, { ignoreQueryPrefix: true });
return qs.parse(searchParams, { ignoreQueryPrefix: true });
}, [pathname]);

const fn = React.useCallback(() => {
const parsedQuery = parse(query as Record<string, string>, {
const parsedQuery = qs.parse(query as Record<string, string>, {
ignoreQueryPrefix: true,
});
const combinedParams = {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-router-v6/src/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ResourceContext,
} from "@refinedev/core";
import { useCallback, useContext } from "react";
import { parse, stringify } from "qs";
import qs from "qs";
import {
useNavigate,
useLocation,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const routerBindings: RouterBindings = {
const urlQuery = {
...(keepQuery &&
existingSearch &&
parse(existingSearch, { ignoreQueryPrefix: true })),
qs.parse(existingSearch, { ignoreQueryPrefix: true })),
...query,
};

Expand All @@ -63,7 +63,7 @@ export const routerBindings: RouterBindings = {
const urlTo = to || "";

const fullPath = `${urlTo}${
hasUrlQuery ? stringify(urlQuery, stringifyConfig) : ""
hasUrlQuery ? qs.stringify(urlQuery, stringifyConfig) : ""
}${hasUrlHash ? urlHash : ""}`;

if (type === "path") {
Expand Down Expand Up @@ -104,7 +104,7 @@ export const routerBindings: RouterBindings = {
}

const fn = useCallback(() => {
const parsedSearch = parse(search, { ignoreQueryPrefix: true });
const parsedSearch = qs.parse(search, { ignoreQueryPrefix: true });

const combinedParams = {
...params,
Expand Down
8 changes: 4 additions & 4 deletions packages/remix/src/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ParseResponse,
} from "@refinedev/core";
import { useParams, useLocation, useNavigate, Link } from "@remix-run/react";
import { parse, stringify } from "qs";
import qs from "qs";
import React, { ComponentProps, useCallback, useContext } from "react";
import { paramsFromCurrentPath } from "./params-from-current-path";
import { convertToNumberIfPossible } from "./convert-to-number-if-possible";
Expand Down Expand Up @@ -36,7 +36,7 @@ export const routerBindings: RouterBindings = {
const urlQuery = {
...(keepQuery &&
existingSearch &&
parse(existingSearch, { ignoreQueryPrefix: true })),
qs.parse(existingSearch, { ignoreQueryPrefix: true })),
...query,
};

Expand All @@ -57,7 +57,7 @@ export const routerBindings: RouterBindings = {
const urlTo = to || "";

const fullPath = `${urlTo}${
hasUrlQuery ? stringify(urlQuery, stringifyConfig) : ""
hasUrlQuery ? qs.stringify(urlQuery, stringifyConfig) : ""
}${hasUrlHash ? urlHash : ""}`;

if (type === "path") {
Expand Down Expand Up @@ -98,7 +98,7 @@ export const routerBindings: RouterBindings = {
const inferredId = inferredParams.id;

const fn = useCallback(() => {
const parsedSearch = parse(search, { ignoreQueryPrefix: true });
const parsedSearch = qs.parse(search, { ignoreQueryPrefix: true });

const combinedParams = {
...inferredParams,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix/src/parse-table-params.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { parse } from "qs";
import qs from "qs";
import type { ParsedParams } from "@refinedev/core";

export const parseTableParams = (search: string) => {
const parsed: ParsedParams = parse(search, { ignoreQueryPrefix: true });
const parsed: ParsedParams = qs.parse(search, { ignoreQueryPrefix: true });

const tableReady = {
...parsed,
Expand Down
12 changes: 6 additions & 6 deletions packages/strapi-v4/src/dataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataProvider as IDataProvider, HttpError } from "@refinedev/core";
import { AxiosInstance } from "axios";
import { stringify } from "qs";
import qs from "qs";
import {
axiosInstance,
generateFilter,
Expand Down Expand Up @@ -41,7 +41,7 @@ export const DataProvider = (
};

const { data } = await httpClient.get(
`${url}?${stringify(query, {
`${url}?${qs.stringify(query, {
encodeValuesOnly: true,
})}&${queryFilters}`,
);
Expand Down Expand Up @@ -78,7 +78,7 @@ export const DataProvider = (
};

const { data } = await httpClient.get(
`${url}?${stringify(query, {
`${url}?${qs.stringify(query, {
encodeValuesOnly: true,
})}&${queryFilters}`,
);
Expand Down Expand Up @@ -199,7 +199,7 @@ export const DataProvider = (
publicationState,
};

const url = `${apiUrl}/${resource}/${id}?${stringify(query, {
const url = `${apiUrl}/${resource}/${id}?${qs.stringify(query, {
encode: false,
})}`;

Expand Down Expand Up @@ -248,7 +248,7 @@ export const DataProvider = (
if (sorters) {
const sortQuery = generateSort(sorters);
if (sortQuery.length > 0) {
requestUrl = `${requestUrl}&${stringify({
requestUrl = `${requestUrl}&${qs.stringify({
sort: sortQuery.join(","),
})}`;
}
Expand All @@ -260,7 +260,7 @@ export const DataProvider = (
}

if (query) {
requestUrl = `${requestUrl}&${stringify(query)}`;
requestUrl = `${requestUrl}&${qs.stringify(query)}`;
}

let axiosResponse;
Expand Down
4 changes: 2 additions & 2 deletions packages/strapi-v4/src/helpers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MetaQuery, pickNotDeprecated } from "@refinedev/core";
import axios from "axios";
import { stringify } from "qs";
import qs from "qs";

interface ILoginResponse {
jwt: string;
Expand Down Expand Up @@ -57,7 +57,7 @@ export const AuthHelper = (apiUrl: string) => ({
};

return await axios.get<IUser>(
`${apiUrl}/users/me?${stringify(query, {
`${apiUrl}/users/me?${qs.stringify(query, {
encodeValuesOnly: true,
})}`,
{
Expand Down
6 changes: 3 additions & 3 deletions packages/strapi-v4/src/utils/generateFilter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CrudFilters, LogicalFilter, ConditionalFilter } from "@refinedev/core";
import { mapOperator } from "./mapOperator";
import { stringify, parse } from "qs";
import qs from "qs";

export const generateNestedFilterField = (field: string) => {
const fields = field.split(".");
Expand Down Expand Up @@ -77,9 +77,9 @@ export const generateFilter = (filters?: CrudFilters) => {
});
}

const parsedQuery = parse(rawQuery, { depth: 15 });
const parsedQuery = qs.parse(rawQuery, { depth: 15 });

const queryFilters = stringify(parsedQuery, { encodeValuesOnly: true });
const queryFilters = qs.stringify(parsedQuery, { encodeValuesOnly: true });

return queryFilters;
};

0 comments on commit c2ef59b

Please sign in to comment.