Skip to content

SSG/JSX: SSG supports Suspense #1977

@yusukebe

Description

@yusukebe

What is the feature you are proposing?

Currently, the SSG Helper does not fully support Suspense.

For example, consider the following example, which returns JSX with AsyncComponet wrapped in Suspense:

app.get('/shops', async (c) => {
  return c.render(
    <div>
      <Suspense fallback={'loading...'}>
        <Component />
      </Suspense>
    </div>
  )
})

The HTML exported by SSG is as follows:

<html>
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <link href="/static/style.css" rel="stylesheet"/>
    </head>
    <body>
        <header>
            <a href="/">top</a>
            <a href="/about">about</a>
            <a href="/shops">shops</a>
        </header>
        <main>
            <div>
                <template id="H:1"></template>
                loading...
                <!--/$-->
            </div>
        </main>
        <footer>
            <address>
                <a href="https://github.com/yusukebe/ramen-api">powered by Ramen API</a>
            </address>
        </footer>
    </body>
</html>
<template>
    <ul>
        <li>
            <a href="/shops/yoshimuraya">yoshimuraya</a>
        </li>
        <li>
            <a href="/shops/sugitaya">sugitaya</a>
        </li>
        <li>
            <a href="/shops/takasagoya">takasagoya</a>
        </li>
    </ul>
</template>
<script>
    ((d,c,n)=>{
        c = d.currentScript.previousSibling
        d = d.getElementById('H:1')
        if (!d)
            return
        do {
            n = d.nextSibling;
            n.remove()
        } while (n.nodeType != 8 || n.nodeValue != '/$')d.replaceWith(c.content)
    }
    )(document)
</script>

I would like to show only the list of shops without loading.... This means that the SSG should be executed with the AsyncComponent in Suspense resolved.

However, if we need to add a lot of code to resolve this issue, we can just write in the documentation that "SSG does not support Suspense completely".

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions