#SolidJS "createResource" having issues at first build

2 messages · Page 1 of 1 (latest)

full bison
#

I've come across a very weird issue. For reference, my project uses Astro in SSR mode with Solid. I have one .tsx component, which uses the createResource module for API request handling. The excerpt of my code:

import { Suspense, createResource, createSignal } from "solid-js"
const [response] = createResource(formData, postFormData)

This all works great - apart from the very first time I run npm run start. At this first instance, I get Vite errors stating

|- TypeError: Cannot read properties of undefined (reading 'id')
    at Proxy.createResource (file://./node_modules/solid-js/dist/server.js:438:35)
    at eval (eval at instantiateModule (file:///./node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54402:28), <anonymous>:20:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async instantiateModule (file:///./node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)```
This error points at the server.js provided by Solid, inside the section for the createResource module:
```js
const sharedConfig = {};
function setHydrateContext(context) {
  sharedConfig.context = context;
}
const SuspenseContext = createContext();
let resourceContext = null;
function createResource(source, fetcher, options = {}) {
  const id = sharedConfig.context.id + sharedConfig.context.count++;
                                  ^ it errors right here
}```
The way I currently solve this is by commenting out the `const [response = ...` line and saving, letting Vite reload the site which now errors due to undefined values (obv), then I uncomment the line and save again, vite reloads and the page works from now on, until I kill the `astro dev` session. This wasnt an issue during development, but now that I'm trying to host the page, I think its causing problems with pageload.
#

(cont) I've got a node adapter set up to host the SSR page. After building the site and starting the node server, opening the page returns an error 500, but the API is still accessible via curl, making me think that the landing page might be affected by the same error I get during development.