Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ssr settings less strict #64

Open
MrFoxPro opened this issue Oct 19, 2022 · 3 comments
Open

Make ssr settings less strict #64

MrFoxPro opened this issue Oct 19, 2022 · 3 comments

Comments

@MrFoxPro
Copy link

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
};
@ryansolid
Copy link
Member

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

@MrFoxPro
Copy link
Author

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

@MrFoxPro MrFoxPro changed the title Make ssr settings less trict Make ssr settings less strict Jul 13, 2023
@MrFoxPro
Copy link
Author

MrFoxPro commented Jul 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants