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

fix: Wrong logic for render decorator #1147

Open
shushanfx opened this issue May 25, 2023 · 0 comments
Open

fix: Wrong logic for render decorator #1147

shushanfx opened this issue May 25, 2023 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@shushanfx
Copy link

Description

I added a @Render() decorator for one of my routes, but other routes were also affected. I debuged into the code, and in KoaDriver, I found this:

    else if (action.renderedTemplate) {
      // if template is set then render it // TODO: not working in koa
      const renderOptions = result && result instanceof Object ? result : {};

      this.koa.use(async function (ctx: any, next: any) {
        await ctx.render(action.renderedTemplate, renderOptions);
      });
    }

This could result in the following two results:

  1. Affect other routes which are not marked with @Render decorator.
  2. Register a middleware for koa for every @Render request.

Solution

I suggest change this code to this.

       else if (action.renderedTemplate) {
            const renderOptions = result && result instanceof Object ? result : {};
            return Promise.resolve(
                    options.context.render(action.renderedTemplate, renderOptions)
                ).then(() => options.next())
        }
@shushanfx shushanfx added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant