https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • s

    Skye

    02/21/2023, 6:00 PM
    Copy code
    console.error("renderToReadableStream error"); // Error thrown from here
            console.error(error);
    Which error is being thrown?
  • s

    sdev

    02/21/2023, 6:12 PM
    TypeError: Cannot read properties of undefined (reading 'sort') It seems that the data in
    const data = useLoaderData<typeof loader>();
    is not sent by Stream.
  • s

    sdev

    02/21/2023, 6:12 PM
    data.something is sorted in block.
  • s

    sdev

    02/21/2023, 6:13 PM
    data.something
    is
    undefined
    . In Workers, it resolves to the value of the Promise.
  • s

    sdev

    02/21/2023, 6:14 PM
    But in functions I got
    undefined
    . Not sure if this comes from remix side or not.
  • s

    sdev

    02/21/2023, 6:16 PM
    However, if the functions is similar to workers, it should work. Not sure if WebStreams Api in functions is different?
  • s

    Skye

    02/21/2023, 6:16 PM
    There's nothing obviously wrong to me there - but I admittedly don't know much about remix
  • s

    Skye

    02/21/2023, 6:16 PM
    I'd suggest making an issue on the remix repo
  • s

    sdev

    02/21/2023, 6:17 PM
    Maybe I should create a reproduction of it.
  • s

    sdev

    02/21/2023, 6:17 PM
    Thank you.
  • d

    Dani Foldi

    02/21/2023, 6:46 PM
    Could it be an old compatibility date and missing stream flags?
  • d

    Dani Foldi

    02/21/2023, 6:47 PM
    If you go to your Pages project > settings > functions, what dates do you see?
  • d

    Dani Foldi

    02/21/2023, 6:48 PM
    Docs: https://developers.cloudflare.com/workers/platform/compatibility-dates/#streams-constructors
  • s

    sdev

    02/21/2023, 7:03 PM
    I'm reproducing a new repo for the issue. Now it seems to work on Chrome based browsers. But not in Safari. This is weird.
  • d

    Dani Foldi

    02/21/2023, 7:04 PM
    Ah so it’s a client side thing, sorry 😅
  • s

    sdev

    02/21/2023, 7:04 PM
    Remix does not have an official guide to build an artifact for Pages functions yet.
  • s

    sdev

    02/22/2023, 6:14 AM
    https://discord.com/channels/595317990191398933/1077741496222097408/1077831324280299540 This is the reason why defer does not work. The Safari (iOS devices) require a minimum amount of data that needs to be loaded before any content is displayed on the page. So to solve the issue, we need to send more data to the initial render to make Safari work properly.
  • s

    sdev

    02/22/2023, 9:02 AM
    Anyone knows a way to use octokit in Functions (functions does not have --node-compat like workers)?
    Copy code
    ts
    const octokit = new Octokit({ auth: gitHubToken });
    Octokit relies on
    crypto
    lib.
  • h

    HardAtWork

    02/22/2023, 9:06 AM
    I tried that once for a project that would commit changes to GH. In the end, I just manually wrote out the commands from the docs.
  • s

    sdev

    02/22/2023, 9:07 AM
    So the solution is to use
    fetch
    with
    Authorization: Bearer ${token}
    right?
  • h

    HardAtWork

    02/22/2023, 9:08 AM
    That's what I did
  • s

    sdev

    02/22/2023, 9:09 AM
    Thank you. Hope someone ports octokit to use web crypto instead of crypto.
  • h

    HardAtWork

    02/22/2023, 9:11 AM
    What are you trying to do? If you are making a commit like I am, I can lend you my code
  • s

    sdev

    02/22/2023, 9:17 AM
    Thank you so much. I appreciate it.
  • s

    sdev

    02/22/2023, 1:27 PM
    Copy code
    ts
    const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
    const response = await fetch(url, {
          method: "GET",
          headers: {
            Accept: "application/vnd.github+json",
            Authorization: `Bearer ${token}`,
            "X-GitHub-Api-Version": "2022-11-28",
          },
        });
    I can use curl with my token to fetch content from a private repo. But when use fetch in Functions, I got Fobidden response.
  • s

    sdev

    02/22/2023, 1:36 PM
    https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#user-agent-required Found the answer. I have to include User-Agent header.
  • p

    Pause

    02/22/2023, 6:30 PM
    This might not be possible, but I'm currently looking for a way to modify the footer on all pages with HTMLRewriter, but if I do a root-level
    _middleware.ts
    , it also runs on GET requests for images and other assets... which causes those assets to fail to be delivered because HTMLRewriter can't rewrite an image.
  • p

    Pause

    02/22/2023, 6:31 PM
    Is there a way to know if a GET request is for a page only?
  • j

    James

    02/22/2023, 7:22 PM
    You would probably want to
    const asset = await next()
    , check the headers of
    asset
    for html
    content-type
    , and then either run
    HTMLRewriter
    , or just continue
  • j

    James

    02/22/2023, 7:22 PM
    your Function will still run (and therefore be billed for invocations though)
1...348349350...392Latest