Skip to content

fix: fix a resource a type error when using async _resolved function #7426

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

JerryWu1234
Copy link
Contributor

@JerryWu1234 JerryWu1234 commented Mar 15, 2025

What is it?

fixes: #7086

follow version 2 to fix this ts error

Description

Checklist

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I made corresponding changes to the Qwik docs
  • I added new tests to cover the fix / functionality

@JerryWu1234 JerryWu1234 requested review from a team as code owners March 15, 2025 03:34
Copy link

changeset-bot bot commented Mar 15, 2025

🦋 Changeset detected

Latest commit: 872fe37

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik-city Patch
@builder.io/qwik Patch
eslint-plugin-qwik Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@JerryWu1234 JerryWu1234 marked this pull request as draft March 15, 2025 03:42
@JerryWu1234 JerryWu1234 marked this pull request as ready for review March 15, 2025 06:44
Copy link

pkg-pr-new bot commented Mar 15, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@builder.io/qwik@7426
npm i https://pkg.pr.new/@builder.io/qwik-city@7426
npm i https://pkg.pr.new/eslint-plugin-qwik@7426
npm i https://pkg.pr.new/create-qwik@7426

commit: 872fe37

Copy link
Contributor

github-actions bot commented Mar 15, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 872fe37

@JerryWu1234 JerryWu1234 self-assigned this Mar 15, 2025
@JerryWu1234 JerryWu1234 moved this from Backlog to Waiting For Review in Qwik Development Mar 19, 2025
@JerryWu1234
Copy link
Contributor Author

@maiieul please help me to review

@@ -886,7 +886,7 @@ export interface ResourceProps<T> {
// (undocumented)
onRejected?: (reason: Error) => JSXOutput;
// (undocumented)
onResolved: (value: T) => JSXOutput;
onResolved: (value: T) => JSXOutput | Promise<JSXOutput>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should also change the type for onPending and onRejected

const resource = props.value as ResourceReturnInternal<T> | Promise<T> | Signal<T>;
let promise: Promise<T> | undefined;
if (isResourceReturn(resource)) {
if (isResourceReturn(resource) && resource.value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add the && resource.value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to add the && resource.value?

Maybe resource is signal @maiieul

Copy link
Member

Choose a reason for hiding this comment

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

the resource is always a promise, no?

This commit refactors the preloader and bundle graph handling to improve performance and maintainability. Key changes include:

- Removed `qwikloader-prefetch.ts` and `qwikloader-entry.ts` as they are no longer needed.
- Updated the preloader configuration to use more descriptive variable names and optimized preload probabilities.
- Changed the bundle graph output from `.js` to `.json` for better clarity and compression.
- Added a new test for the preloader script to ensure its integrity and size.
- Updated API Extractor configurations across multiple packages to use consistent naming and newline settings.

These changes aim to enhance the efficiency of Qwik's preloading mechanism and ensure better maintainability of the codebase.
Copy link
Member

@wmertens wmertens left a comment

Choose a reason for hiding this comment

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

Can you explain more why this is needed? A Resource is supposed to be a placeholder for a Promise, so I don't understand why it should also return a Promise

Comment on lines +194 to +195
onResolved: (value: T) => JSXOutput | Promise<JSXOutput>;
onPending?: () => JSXOutput | Promise<JSXOutput>;
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this is needed. The resource holds a Promise, but the Resource component should just render without a Promise

const resource = props.value as ResourceReturnInternal<T> | Promise<T> | Signal<T>;
let promise: Promise<T> | undefined;
if (isResourceReturn(resource)) {
if (isResourceReturn(resource) && resource.value) {
Copy link
Member

Choose a reason for hiding this comment

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

the resource is always a promise, no?

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

Successfully merging this pull request may close these issues.

[🐞] onResolved cannot return a Promise
3 participants