Skip to content

Feature Request: make data in +page.ts a function that lazily load data from the server #13034

@paoloricciuti

Description

@paoloricciuti

Describe the problem

Today the data argument we get in the universal load function is eagerly evaluated

const res = await native_fetch(data_url.href);

this is mostly fine but it would be cool if instead we could lazily load the server data in the universal load function in case we don't need it.

What this would allow is having the ability to cache something client side and have the server load function be invoked only if we don't have client data...something like this eg.

let cached_data;

export async function load({ data }){
    cached_data ??= await data();
    return {
        ...cached_data,
    };
}

this would basically prevent a trip to the server for data that we might know it's already in the client.

Describe the proposed solution

Turn data in a function so that the user can call that lazily. Obviously in case we don't have an universal load function we should just call it ourselves to pass data to the component.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeneeds-decisionNot sure if we want to do this yet, also design work needed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions