Skip to content

AudioPlayerLite: fix 'originalComponent is not a function' on the second scene opened - #754

Merged
DogmaDragon merged 1 commit into
stashapp:mainfrom
nd4y:fix/audioplayerlite-duplicate-patch
Aug 11, 2026
Merged

AudioPlayerLite: fix 'originalComponent is not a function' on the second scene opened#754
DogmaDragon merged 1 commit into
stashapp:mainfrom
nd4y:fix/audioplayerlite-duplicate-patch

Conversation

@nd4y

@nd4y nd4y commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The bug

Opening a scene works right after a page load, but every scene opened afterwards (without reloading) fails with the generic "Something went wrong." page:

TypeError: originalComponent is not a function
    at Object.apply (assets/index-*.js)
    ...
    at jt (assets/Scene-*.js)

Reloading the page makes it work again — once.

Cause

The plugin registers its patch inside the stash:location handler, so every navigation to /scenes/<id> pushes another copy of the same function onto insteadFns["ScenePlayer"]patch.instead() only appends, it never deduplicates.

Once there is more than one patch in the chain, runInstead() (ui/v2.5/src/patch.tsx) hands each patch the next one as a trailing argument:

return fns[0].apply(thisArg, argArray.concat(next()));
// next() returns a Proxy: apply: (target, ctx, args) => target.apply(ctx, args.concat(next()))

React calls a function component as (props, secondArg), which is why the first patch correctly receives the original as its third argument. But the plugin invokes it as originalComponent({ ...props, scene }) — a single argument — so the proxy passes (props, next) to the second copy. There the original component lands in the second parameter and the third one is undefined, hence originalComponent is not a function, thrown from the proxy's apply trap.

The fix

  • Register the patch only once per page load.
  • Render the original through React.createElement(originalComponent, ...) instead of calling it with one argument, so the chain still works if another plugin patches ScenePlayer as well.
  • Call setStyle() instead of poster(), which is not defined anywhere in the file and would throw a ReferenceError as soon as an actual audio file was opened.
  • Guard props.scene.files[0] against scenes with no files.
  • Version bumped 0.1 → 0.2 so existing installs pick the fix up.

Testing

The patched file is deployed on my own instance, where this error was breaking scene playback regularly. node ./validate.js --ci passes.

Disclosure

The patch was drafted with LLM assistance; I reviewed it and tested it on my own instance, and I take responsibility for the code.

The patch was registered inside the stash:location handler, so every
navigation to a scene pushed another copy onto insteadFns["ScenePlayer"].
With more than one patch in the chain, runInstead() passes the next patch
as an extra trailing argument, so the second copy receives the original
component as its second argument and reads undefined as the third one,
failing with "TypeError: originalComponent is not a function". Only the
first scene opened after a page load worked; every later one errored out
until the page was reloaded.

Register the patch once, and render the original component through
React.createElement instead of calling it with a single argument, so the
patch chain keeps working if another plugin patches ScenePlayer too.

Also call setStyle() instead of the undefined poster(), and guard against
scenes with no files.
@nd4y

nd4y commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Tested in the browser on my own instance: opened several scenes back to back without reloading the page — the error no longer occurs and the player behaves as before. Previously the second scene opened after a page load failed every time.

@discourse-stashapp

Copy link
Copy Markdown

This pull request has been mentioned on Stash Forum. There might be relevant details there:

https://discourse.stashapp.cc/t/audioplayerlite/1329/3

@DogmaDragon DogmaDragon added the type:plugin Plugins label Aug 11, 2026
@DogmaDragon
DogmaDragon merged commit c41f44a into stashapp:main Aug 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants