solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
5.13k stars 376 forks source link

[Bug?]: Re-execution of entry-client.tsx When Importing SharedWorker in SolidStart #1628

Closed KiaClouth closed 3 weeks ago

KiaClouth commented 4 weeks ago

Duplicates

Latest version

Current behavior 😯

Every time I import and use DataWorker in different components, entry-client.tsx is re-executed. This issue does not occur in a basic Vite project, so it seems specific to SolidStart.

Expected behavior 🤔

entry-client.tsx should only execute once, and DataWorker should be reusable across components without causing re-execution of the entire file.

Steps to reproduce 🕹

codesandbox example

Steps:

1.Create an empty dataworker.ts file
2.In entry-client.tsx, I initialize a SharedWorker: import dataWorker from "~/worker/dataWorker?sharedworker"; export const DataWorker = new dataWorker; 3.Import the sharedworker in routes/index.tsx: import { DataWorker } from "~/entry-client"; const dw = DataWorker; 4.pnpm dev 5.The problem arises when the component is loaded. The entry-client.tsx file is re-executed, and this happens each time I import and use DataWorker in other components.

Context 🔦

I plan to perform intensive computations in a worker thread and share this data between multiple windows.

Your environment 🌎

System: windows 11
Browser: Chrome 128.0.6613.138
solidjs:1.8.22
@solid-start: 1.0.6
KiaClouth commented 3 weeks ago

Moving the shared worker initialization code from entry-client.tsx to a separate file resolved the issue.

Thanks to ryansolid for the suggestion, and this has resolved my problem.