Skip to content

Commit

Permalink
Merge pull request #7263 from damianpumar/fix/remove-proxy-function-7254
Browse files Browse the repository at this point in the history
fix(core): store property descriptor handling
  • Loading branch information
wmertens authored Jan 22, 2025
2 parents af8fd6d + 1c96674 commit b8bfe22
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/qwik/src/core/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,20 @@ export class ReadWriteProxyHandler implements ProxyHandler<TargetType> {
: a;
});
}

getOwnPropertyDescriptor(
target: TargetType,
prop: string | symbol
): PropertyDescriptor | undefined {
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);

if (isArray(target) || typeof prop === 'symbol') {
return Object.getOwnPropertyDescriptor(target, prop);
return descriptor;
}

if (descriptor && !descriptor.configurable) {
return descriptor;
}

return {
enumerable: true,
configurable: true,
Expand Down
48 changes: 48 additions & 0 deletions starters/apps/qwikcity-test/src/routes/issue7254/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { component$, Resource, useResource$, useStore } from "@builder.io/qwik";

import { server$ } from "@builder.io/qwik-city";

export interface Hello {
print: string;
}

const hello = server$((hello: Hello) => {
// Error: 'getOwnPropertyDescriptor' on proxy: trap returned descriptor for property 'print' that is incompatible with the existing property in the proxy target
return helloBar(hello);
});

const helloBar = server$(
(hello: Hello): Promise<string> =>
new Promise((res) => {
setTimeout(() => {
res(hello.print + " Bar");
}, 200);
}),
);
export default component$(() => {
const helloStore = useStore<Hello>({ print: "hello" });
const resource = useResource$(({ track }) => {
track(() => helloStore.print);

return hello(helloStore);
});

return (
<>
<Resource
value={resource}
onPending={() => <div>Loading...</div>}
onRejected={(error) => <div>Error: {error.message}</div>}
onResolved={(data) => <div>Data: {data}</div>}
/>

<button
onClick$={() => {
helloStore.print = "Foo";
}}
>
Reset
</button>
</>
);
});
13 changes: 13 additions & 0 deletions starters/e2e/qwikcity/resource.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "@playwright/test";

test.describe("Resource", () => {
test("should handle the resource correctly", async ({ page }) => {
await page.goto("/qwikcity-test/issue7254/");

await page.getByText("Data: hello Bar");

await page.getByRole("button", { name: "Reset" }).click();

await expect(page.getByText("Data: Foo Bar")).toBeVisible();
});
});

0 comments on commit b8bfe22

Please sign in to comment.