Closed thetarnav closed 1 year ago
Hmm.. yeah Rollup has changed over the years as it used to work and stopped. We do have something we use internally for this maybe I should expose it. I was probably thinking this was only an internal concern but yeah it could affect reusable libraries.
https://github.com/solidjs/solid/blob/main/packages/solid/src/render/component.ts#L14-L17
Describe the bug
From what I understand, the current way to check if the code runs during hydration would be to check if
sharedConfig.context
exists. This - together withisServer
- could allow library authors to handle SSR / CRS / CRS + hydration cases differently. (example: https://stackblitz.com/edit/github-tzjxcu-xofarw?file=src%2Fcomponents%2FTest.tsx prompted by this issue)But this way of checking it is not tree-shakeable. If we build a SPA that doesn't hydrate, the code for the hydration path will still remain. I know this is not as simple as having a const
isServer
variable, but if there is nothing to set the hydration context, anything that relies on it could be tree-shaken, right?Also I'm noticing that code from solid-js that uses it remains too, so this could be improved as well
Your Example Website or App
https://stackblitz.com/edit/solid-hydration-treeshaking?file=dist%2Fassets%2Findex-f7669aee.js&file=src%2FApp.tsx
Steps to Reproduce the Bug or Issue
pnpm build
if (sharedConfig.context) {}
remainsExpected behavior
code paths that won't ever run should be removed from the end bundle