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

SSG route called #3088

Open
RobertSasak opened this issue Jul 4, 2024 · 11 comments
Open

SSG route called #3088

RobertSasak opened this issue Jul 4, 2024 · 11 comments
Labels

Comments

@RobertSasak
Copy link
Contributor

RobertSasak commented Jul 4, 2024

What version of Hono are you using?

4.4.11

What runtime/platform is your app running on?

NodeJS

What steps can reproduce the bug?

// build.ts
import fs from 'fs/promises'
import { Hono } from 'hono'
import { ssgParams, toSSG } from 'hono/ssg'

const app = new Hono()
app.get(
    '/shops/:id',
    ssgParams(() => [{ id: 'shop1' }]),
    async (c) => {
        const id = c.req.param('id')
        console.warn(id)
        return c.html(id)
    },
)

toSSG(app, fs)
$ npx vite-node src/build.ts

What is the expected behavior?

It is expected to log

shop1

What do you see instead?

:id
shop1

Additional information

Route is called twice instead of once. First time the route is called the parameter id is not replaced with the actual value but stays ":id".

I think it might be related to #2175

@RobertSasak RobertSasak added the bug label Jul 4, 2024
@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jul 5, 2024

I'll look abt this

@EdamAme-x
Copy link
Contributor

hi @RobertSasak
Does this mean that when I access "/shop1" it is logged?
Or are you talking about "/:id is also generated"?

@EdamAme-x
Copy link
Contributor

@EdamAme-x
Copy link
Contributor

@RobertSasak
Copy link
Contributor Author

I run vite to command to produce static pages. ssgParams define only one page to be generated. It has id="shop1". However actual route get called twice. First time with a id=":id" and second time with id="shop1".

Only one static page is actually produced on the disk(shop1.html). However during my test I also saw ":id.html" created on the disk. I am not sure how to reproduce it.

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jul 5, 2024

hmm...
Looking at the code, it does not seem to be generated
@RobertSasak

@yusukebe
Copy link
Member

yusukebe commented Jul 5, 2024

Hi @RobertSasak

This is a known issue. We may fix it.

@yusukebe
Copy link
Member

yusukebe commented Jul 5, 2024

@watany-dev @sor4chi @nakasyou @usualoma Do you have any idea?

@RobertSasak
Copy link
Contributor Author

RobertSasak commented Jul 5, 2024

Thank you for following up this issue. I don't think it is necessary to spend energy on it as there is a simple workaround for it. I expected it will be fixed onced the question whether SSG should be middleware or not.

const id = c.req.param('id')
if (id==':id') {
    return c.html('Ignored', 500) // https://github.com/honojs/hono/issues/3088
}

@nakasyou
Copy link
Contributor

nakasyou commented Jul 5, 2024

When I implemented this, I couldn't find how to resolve this.

However, application users can access /shops/:id when it isn't on SSG, so I think there is no problem.

@nakasyou
Copy link
Contributor

nakasyou commented Jul 5, 2024

I have an idea.

What do you think about allowing ssgParams to response params as JSON when request is for SSG?
In this solution, it will be returned early, so after handler will not be called. But we must set disableSSG and onlySSG before ssgParams, it may be breaking change.

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

4 participants