question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New "Framework" which renders server-side routes

See original GitHub issue

Is your feature request related to a problem? Please describe We have an express app that powers a lot of different pages, it does not use a single framework and does not have an easy way to render directly to html. Knowing what routes are available requires digging through code for the express routers.

Describe the solution you’d like Being able to provide a *.stories.ts file next to each route which looks something like:

export default  {
  title: "Product/Product Page"
  route: "/product/:productid",
  argsTypes: {
    productid: {
      control: {
        type: "select",
        options: ["product-id-1", "product-id-2", "product-id-3"]
      }
    }
  }
}

Then in storybook this would load <base-url>/product/product-id-1 in the preview iframe and changing the productid control would reload it replacing :productid with the respective id. This could be extended to also support query parameters and hash values and maybe POST body data as well.

Describe alternatives you’ve considered Currently we just have a page of links, which does not regularly get updated and is not overly used. Making storybook the primary interaction point locally would likely solve that issue.

There are likely already products that solve this problem, however we use storybook for our design-system and using the fairly recent Storybook Composition feature to bring the documentation inside our main application dev environment would be fantastic.

Are you able to assist to bring the feature to reality? Potentially.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jonspalmercommented, Mar 28, 2021

@shilman is right. You need that change but its very simple to setup Storybook Server by hand. I suspect from your description that server will be what you need. I would expect you do write a few stories as json and off you go. It might be that you can auto generate the json from your other code much like we do with this gem for Rails: https://github.com/jonspalmer/view_component_storybook. I’d be happy to collaborate on that and figure out what it might look like.

0reactions
jonspalmercommented, Jun 19, 2021

@AndrewLeedham a root story is likely possible. I suspect its’ a simple bug somewhere (Though IMO a story ‘without an id’ is a slightly strange idea. In my projects I’d want to make it explicit)

Supporting path params as well as just query params is likely pretty doable.

The details for all this are here: https://github.com/storybookjs/storybook/blob/next/app/server/src/client/preview/render.ts#L10

You can see how the request is constructed from the various params. It’s not that hard to see how you could pick out variables in the path and substitute them with param values. The good news is you can customize the fetch function: https://github.com/storybookjs/storybook/tree/next/app/server#fetchstoryhtml

Perhaps you can experiment with that feature. If there is a good general purpose solution submit it as a PR and we can support it out the box?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 3 JavaScript Frameworks for Server-side Rendering in 2022
Based on the above pros and cons, and surveys, we can conclude that NextJS is the best serverside rendering framework for future implementations....
Read more >
A Look At Remix And The Differences With Next.js
Let's talk about Remix, the (kind of) new framework to create JavaScript projects using server-side rendering. Let's go through its main ...
Read more >
Server-side rendering frameworks - Medium
Angular. Angular is a JavaScript framework built by Google. It provides APIs for HTTP transactions, routing, service workers, metadata, etc.
Read more >
Different SSR server side rendering framework – @tkssharma
Next.js does routing automatically by the file name so we don't have to worry about that. Pages with Dynamic Routes If we want...
Read more >
The Return of Server Side Routing - DEV Community ‍ ‍
The "modern" JavaScript framework is designed to build applications. Single Page Applications. A name originated from the fact that it does not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found