solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
32.21k stars 917 forks source link

Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'data' in undefined #1811

Open XiNiHa opened 1 year ago

XiNiHa commented 1 year ago

Describe the bug

When server-created createResource got read after getting resolved, Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'data' in undefined error happens on the server.

Your Example Website or App

https://github.com/XiNiHa/solid-relay/tree/feat/ssr-defer

Steps to Reproduce the Bug or Issue

  1. Clone the repo with feat/ssr-defer branch
  2. pnpm i, pnpm build, cd examples/ssr, pnpm dev
  3. Open the index route (with Firefox, as mentioned below)
  4. Refresh the page until the page is broken. (no content after Additional data... fallback goes away) Found that this bug only happens occasionally.
  5. Check the browser console to see the error streamed in.

Expected behavior

I expected the resource to resolve without triggering any errors.

Screenshots or Videos

Expected behavior:

https://github.com/solidjs/solid/assets/8155259/7d14604c-b65e-4cb3-8690-c3de5e67f4e8

Bug happening:

https://github.com/solidjs/solid/assets/8155259/5e40f58a-acaf-41ae-a4ea-472547bffb5a

Platform

Additional context

The exact position where the error is happening is here (verified by monkey-patching the code. adding sharedConfig.context!.resources[id] && check before the in prevented the error from happening, but then made another error happen at here by accessing .data in undefined)

Monkey-patching to replace all sharedConfig.context!.resources[id] access in read() to resource resolved the issue.

The bug happens much less frequently in a Private Window.

ryansolid commented 12 months ago

This is an odd issue. I never reproduced it ever in Chrome, and the only thing that resembled it Firefox it wasn't the same errors you were getting. It was name or metadata of undefined which I couldn't find the code for. And even after applying both fixes I could still reproduce it.

Screenshot 2023-10-09 at 2 35 59 PM

Even stranger is that if we assume you made your first fix, there is no way during synchronous code execution the second issue like you pointed at could error. If your condition prevented it from being resolved how could that branch of the ternary ever execute?

For the browser to make a difference on server code seems highly unlikely unless maybe this something related to the development environment. Did you ever try running this in prod mode (I had no luck it was trying to open up an invalid port)?

Right now I can confirm there is something up, but I can't reproduce the issue you were having or its relation to Solid code.

nbrugger-tgm commented 3 weeks ago

I had the same error message when instantiating a createResource outside of a component.

const res = createResource(..., { deferStream: true });
const Comp = ()=>{
    return <div>{res()}</div>
}
XiNiHa commented 3 weeks ago

Oh right, I have a similar one in my code, creating a chained resource in a resource until the fetch settles. Maybe runWithOwner would help here? I'll try that right now...

XiNiHa commented 3 weeks ago

Oops, turns out that I actually have no code like that 😅 However it feels like I'm somehow reaching the root cause of the issue... I'll keep the further investigation.

ErwanLeroux commented 1 week ago

I had a similar problem, but it was right after i rebase a branch that modified the pnpm-lock.yaml on anotther branch that contained another modified pnpm-lock.yaml. I solved by deleting the file and running install again