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

Using chess.js in Quasar/Vue app has issues with _positionCounts when used in pinia store #446

Open
NeverNerfLabsAdmin opened this issue Feb 14, 2024 · 2 comments

Comments

@NeverNerfLabsAdmin
Copy link

I didn't see this problem until I moved chess.js into a pinia store but that seemed to change how _positionCounts was running. I started getting this error:
TypeError: fen.split is not a function
at trimFen (chess.ts:535:14)
at Object.get (chess.ts:585:22)
at Proxy.toString ()
at toTypeString (shared.esm-bundler.js:40:48)
at toRawType (shared.esm-bundler.js:42:10)
at getTargetType (reactivity.esm-bundler.js:862:93)
at createReactiveObject (reactivity.esm-bundler.js:917:22)
at reactive (reactivity.esm-bundler.js:868:10)
at MutableReactiveHandler.get (reactivity.esm-bundler.js:464:44)
at Proxy.load (chess.ts:661:10)

The issue is here:
this._positionCounts = new Proxy({} as Record<string, number>, {
get: (target, position: string) =>
position === 'length'
? Object.keys(target).length // length for unit testing
: target?.[trimFen(position)] || 0,

When I add a console.log(position) I get the following:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
chess.ts:590 __v_isReadonly
chess.ts:590 __v_isShallow
chess.ts:590 __v_isReadonly
chess.ts:590 __v_raw
chess.ts:590 __v_raw
chess.ts:590 __v_isRef
chess.ts:590 __v_isRef
chess.ts:590 __v_isReadonly
chess.ts:590 __v_raw
chess.ts:590 __v_skip
chess.ts:590 Symbol(Symbol.toStringTag)

It's the last one that causes trimFen(position) to throw the TypeError: fen.split is not a function

For now I have this quick and dirty fix:
get: (target, position: string) => {
console.log(typeof position);
if (typeof position === 'symbol') {
return void 0;
}

But TBH I don't fully understand the problem or cause.

sgr-nz added a commit to NeverNerf-Studio/NeverNerf.Chess that referenced this issue Feb 14, 2024
…le-store

Moved rarity styling into own scss file

Refactored the chessboard inputhandler and fixed various gameState issues

Removed chess.js temporarily and using own version to fix the Symbol bug I found, see: jhlywa/chess.js#446

Made router initialize the chessboard-store

Fixed asset-store.loading
@jhlywa
Copy link
Owner

jhlywa commented Feb 18, 2024

Thanks for the report @NeverNerfLabsAdmin. I'll take a shot at rewriting the position count without the use of a proxy.

@jhlywa
Copy link
Owner

jhlywa commented Feb 24, 2024

I removed the proxy from 1.0.0-beta.8. It's been published to NPM. Let me know if that fixes things for you.

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

No branches or pull requests

2 participants