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

fail if we find any async functions #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fail if we find any async functions #69

wants to merge 1 commit into from

Conversation

brianleroux
Copy link
Contributor

per https://discord.com/channels/1012099764713705472/1012435743571988560/1256006651073396899

detects and fails if we encounter an AsyncFunction in the elements map

Copy link
Contributor

@macdonst macdonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is much more descriptive. Now the error looks like:

Oops, something went wrong
Error: illegal_async_function: doc-content must be a Function not an AsyncFunction
    at renderTemplate (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/index.mjs:203:13)
    at expandTemplate (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/index.mjs:145:16)
    at file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/index.mjs:35:15
    at walk (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/lib/walk.mjs:2:7)
    at walk (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/lib/walk.mjs:14:11)
    at walk (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/lib/walk.mjs:14:11)
    at processCustomElements (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/index.mjs:27:5)
    at html (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/ssr/index.mjs:74:9)
    at html (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/arc-plugin-enhance/src/http/any-catchall/router.mjs:170:24)
    at Object.api (file:///Users/simonmacdonald/Developer/macdonst/tmp/async-throw-test/node_modules/@enhance/arc-plugin-enhance/src/http/any-catchall/router.mjs:216:22)

So it actually points to the root cause.

@brianleroux
Copy link
Contributor Author

I could see the argument to allow for AsyncFunction but feels like thats a bug farm and bad practise anyhow (eg. fetch in a component logic…that logic should be in async handlers rather than ctor / init render)

@macdonst
Copy link
Contributor

@brianleroux no, elements have to be sync. If folks need to fetch data they need to do it before the render method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants