solidjs/vite-plugin-solid

Make ssr settings less strict

Opened this issue · 3 comments

I need to prerender certain pages in ssg mode, so some chunks should be trasnformed with ssr: true option.
However, this condition: https://github.com/solidjs/vite-plugin-solid/blob/master/src/index.ts#L377 requires in my plugin change option explicitly:

function setSSRMode(enable: boolean) {
  if (enable) {
     options.solidPluginOptionsRef.ssr = true
     options.solidPluginOptionsRef.solid!.hydratable = false
  } else {
     options.solidPluginOptionsRef.ssr = _ssr
     options.solidPluginOptionsRef.solid.hydratable = _hydratable
  }
}

async function getEntryFragment(entry: NormalizedEntry) {
  setSSRMode(true)
  const ssrMod = await server.ssrLoadModule(entry.ssrEntry, { fixStacktrace: true })
  setSSRMode(false)
  if (ssrMod.render?.constructor !== Function) {
     throw new Error(`SSG entry ${entry.ssrEntry} should provide 'render' export`)
  }
  const fragment = await ssrMod.render()
  return fragment
}

I suggest something like:

const generate = options.ssr || isSsr ? 'ssr' : 'dom'
const hydratable = isSsr || options.ssr

solidOptions = {
  generate,
  hydratable
};

isSSR means currently ssr transform happening
and options.ssr means enable building ssr output

So logic would be..

const generate = isSSR ? "ssr" : "dom"; // or maybe `options.ssr && isSSR ? "ssr" : "dom"`
const hydratable = options.ssr;

I think but I'm not sure that helps you much. You want to set hydratable to false and still generate "ssr" piggybacking on the option to build ssr seems wrong. I wonder if we can just look at the solid field if it exists

isSSR means currently ssr transform happening and options.ssr means enable building ssr output

So logic would be..

const generate = isSSR ? "ssr" : "dom"; // or maybe `options.ssr && isSSR ? "ssr" : "dom"`
const hydratable = options.ssr;

I think but I'm not sure that helps you much. You want to set hydratable to false and still generate "ssr" piggybacking on the option to build ssr seems wrong. I wonder if we can just look at the solid field if it exists

I need this mostly for distinction: some files transform in SSR mode, another not, respect {ssr: boolean} foremost

From discord [1]

I made SSG prerendering, however, some HTML pages I want to make hydratable, others not.
Currently I can only set hydratable: true or false. I would like avoid injecting my plugin personal plugin to change this flag for every page.
Can we implement hook like hydratable: (entry) => boolean in vite-plugin-solid?
Same with SSR