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

Documentation for SSR without Babel? #889

Closed
Josh-Cena opened this issue Apr 2, 2022 · 10 comments
Closed

Documentation for SSR without Babel? #889

Josh-Cena opened this issue Apr 2, 2022 · 10 comments
Labels

Comments

@Josh-Cena
Copy link

Josh-Cena commented Apr 2, 2022

💬 Questions and Help

Hi, I'm trying to migrate Docusaurus from react-loadable to @loadable/component. Code-splitting is central in our architecture: every route component and its props are loaded as separate chunks. As of now, we use Loadable.Map to load the chunks needed for rendering each component. The chunk names and paths are generated on server-side as a registry.js file, before starting the bundler:

export default {
  // A chunk for a prop
  '001f469f': [() => import(/* webpackChunkName: '001f469f' */ '~blog/blog-tests/tests-blog-tags-blog-821.json'), '~blog/blog-tests/tests-blog-tags-blog-821.json', require.resolveWeak('~blog/blog-tests/tests-blog-tags-blog-821.json')],
  // A chunk for a component
  '010225af': [() => import(/* webpackChunkName: '010225af' */ '@site/_dogfooding/_pages tests/link-tests.tsx'), '@site/_dogfooding/_pages tests/link-tests.tsx', require.resolveWeak('@site/_dogfooding/_pages tests/link-tests.tsx')],
  // 600 more lines...
}

Where each chunk name maps to one loader, one webpack option, and one module option, which we can directly pass to Loadable.Map. There's another routeChunkNames file that maps each route to the chunks that need to be loaded. You can find the source code here, comments inlined: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus/src/client/exports/ComponentCreator.tsx

We don't use the Babel plugin provided by react-loadable, because we allow users to swap out JS loaders, so they may not use Babel (or our Babel config, at least) at all. Instead, because we have our own codegen, dynamically generating thousands of lines of repeating code is not a problem.

My questions are:

  • If I don't use the Babel plugin but choose to leverage our own codegen for generating the options that loadable needs (requireAsync, resolve, etc.), what are the API specs for those options? They seem to be internal and contain a lot of boilerplate, but we are happy to implement whatever loadable requires.
  • Since there's no drop-in replacement for Loadable.Map, does that mean we have to implement our own equivalent with Promise.all, etc.?
  • Does anything else do any static analysis, or would we be able to minimally tweak our current architecture (i.e. a centralized registry for all lazy-loaded chunks, and dynamically passing the options to loadable()) if we don't use the Babel plugin?
@stale
Copy link

stale bot commented Jun 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 12, 2022
@Josh-Cena
Copy link
Author

👋 No response yet!

@stale stale bot removed the wontfix label Jun 12, 2022
@stale
Copy link

stale bot commented Aug 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 13, 2022
@Josh-Cena
Copy link
Author

👋

@stale stale bot removed the wontfix label Aug 13, 2022
@stale
Copy link

stale bot commented Oct 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 16, 2022
@Josh-Cena
Copy link
Author

👋 Sigh is this project even maintained still? Is every such project dead?

@stale stale bot removed the wontfix label Oct 16, 2022
@fivethreeo
Copy link
Contributor

React.lazy is now in react 18, and works on the server.

reactwg/react-18#114

One thing that is missing is "Injecting Into the SSR Stream", should rewrite the babel plugin so we give a Promise to React.lazy no need for the component magic except for a chunkextractor on the server sidethat outputs the tags incrementally.

#718 (comment)

@fivethreeo
Copy link
Contributor

Seems like loadable-compnents has suspense support in client. Will give it a try with react 18 server side suspense and see.

@fivethreeo
Copy link
Contributor

Copied this lazy from react 18, could be adapted to loadable https://codesandbox.io/s/react-18-custom-lazy-1liry3

@stale
Copy link

stale bot commented Jan 7, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 7, 2023
@stale stale bot closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants