Skip to content

Commit

Permalink
fix: cannot sent sync request to server #39
Browse files Browse the repository at this point in the history
  • Loading branch information
condorheroblog committed Dec 26, 2024
1 parent c00bc25 commit d916f81
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/playground/http2-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"typescript": "^5.7.2",
"vite": "^6.0.3",
"vite-plugin-fake-server": "workspace:^",
"vue-tsc": "^2.1.10"
"vue-tsc": "^2.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/playground/react-sample/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { RouterProvider } from "react-router";
import { RouterProvider } from "react-router/dom";

import { router } from "./router";
import "./styles/tailwind.css";
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/vue-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"typescript": "^5.7.2",
"vite": "^6.0.3",
"vite-plugin-fake-server": "workspace:^",
"vue-tsc": "^2.1.10"
"vue-tsc": "^2.2.0"
}
}
18 changes: 16 additions & 2 deletions packages/vite-plugin-fake-server/src/xhook/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ export function xhook() {
let k, modk;
for (k of ["type", "timeout", "withCredentials"]) {
modk = k === "type" ? "responseType" : k;
//The new code belongs to vite-plugin-fake-server
if (modk === "responseType" && !facade._responseTypeChanged) continue;
if (modk in facade) {
request[k] = facade[modk];
}
Expand Down Expand Up @@ -610,8 +612,20 @@ export function xhook() {
facade.responseXML = null;
facade.readyState = 0;
facade.statusText = "";
//The new code belongs to vite-plugin-fake-server
facade.responseType = "";
facade._responseTypeChanged = false;
// The new code belongs to vite-plugin-fake-server
/*====================== START ======================*/
let innerResponseType = "";
Object.defineProperty(facade, "responseType", {
get: () => innerResponseType,
set: (newValue) => {
facade._responseTypeChanged = true;
innerResponseType = newValue;
},
enumerable: true,
configurable: true
});
/*====================== END ======================*/

return facade;
};
Expand Down
57 changes: 28 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d916f81

Please sign in to comment.