Giter VIP home page Giter VIP logo

Comments (11)

brophdawg11 avatar brophdawg11 commented on April 28, 2024 4

The fix for this is out in 1.15.0-pre.1 if anyone wants to give that a spin. We should have a stable 1.15.0 out soon as well.

from blues-stack.

justinwaite avatar justinwaite commented on April 28, 2024 2

@machour I would encourage you to reopen – If you look at the repo (and my instructions above), I'm awaiting the data in the loader, so it should be "instantly" available.

I did find the issue – it's the --bundle flag on the build:server script. If you remove it, everything works as expected.

from blues-stack.

machour avatar machour commented on April 28, 2024 2

🤦🏼‍♂️ sorry @justinwaite, reopened.

from blues-stack.

JDouven avatar JDouven commented on April 28, 2024 1

Any new info regarding this? I'm running into this as well but removing --bundle is not an option for me.

from blues-stack.

brophdawg11 avatar brophdawg11 commented on April 28, 2024 1

This looks to be due to a failing instanceof check across a CJS/ESM boundary when using --bundle. We'll get a fix added for this but in the meantime if you'd like to get past it via patch-package you just need to replace the single check in @remix-run/router:

  // before
  if (result instanceof DeferredData) {

  // after
  if (result &&
      typeof result === "object" &&
      typeof result.data === "object" &&
      typeof result.subscribe === "function" &&
      typeof result.cancel === "function" &&
      typeof result.resolveData === "function") {

You should patch this in all 3 build files to be safe:

  • @remix-run/router/dist/router.js
  • @remix-run/router/dist/router.cjs.js
  • @remix-run/router/dist/router.umd.js

from blues-stack.

justinwaite avatar justinwaite commented on April 28, 2024

Repro repo: https://github.com/justinwaite/blues-stack-defer

from blues-stack.

machour avatar machour commented on April 28, 2024

switching from json to defer is not enough, you have to wrap the deferred data in <Await />

See our guide on streaming: https://remix.run/docs/en/v1/guides/streaming#the-solution

from blues-stack.

justinwaite avatar justinwaite commented on April 28, 2024

If you want, feel free to remove await in the loader and add Suspense and Await in the component. You just don't need to go that far to see the error. The result is the same.

from blues-stack.

MichaelDeBoey avatar MichaelDeBoey commented on April 28, 2024

@justinwaite @JDouven Does it work with the default Remix template?
https://github.com/remix-run/remix/tree/main/templates/remix

from blues-stack.

JDouven avatar JDouven commented on April 28, 2024

@MichaelDeBoey Yes, that works. In my case I serve the app with express instead of remix-serve.

I used the following code:

import { defer } from '@remix-run/node';
import { Await, useLoaderData } from '@remix-run/react';
import { Suspense } from 'react';

export async function loader() {
  const testPromise = new Promise<string>((resolve) => {
    setTimeout(() => {
      resolve('Hello with a delay!');
    }, 3000);
  });

  return defer({
    instantly: 'foo',
    testPromise,
  });
}

export default function Index() {
  const data = useLoaderData<typeof loader>();
  return (
    <div style={{ fontFamily: 'system-ui, sans-serif', lineHeight: '1.4' }}>
      <h1>Welcome to Remix</h1>
      <h2>Instant data:</h2>
      <pre>{data.instantly}</pre>
      <h2>Streamed data:</h2>
      <Suspense fallback={<p>Suspense fallback</p>}>
        <Await
          resolve={data.testPromise}
          errorElement={<p>Await errorElement</p>}
        >
          {(testPromise) => <pre>{testPromise}</pre>}
        </Await>
      </Suspense>
    </div>
  );
}

So I used the express template, and that works too. Then I changed the following to make it more closely match the relevant parts of blues-stack:

  • Rename server.js to server.ts and fix the imports (and npm install missing types)
  • Update package.json to:
"scripts": {
    "build": "remix build",
    "build:server": "esbuild --platform=node --format=cjs ./server.ts --outdir=build --bundle",
    "dev": "run-p dev:*",
    "dev:remix": "remix watch",
    "dev:build": "cross-env NODE_ENV=development npm run build:server -- --watch",
    "dev:server": "cross-env NODE_ENV=development node --inspect --require ./node_modules/dotenv/config ./build/server.js",
}

(inspired by the blues-stack package.json)

When I now run npm run dev my example stops working. The frontend stops receiving loader data completely. Neither the 'instant' data nor the streamed data is visible.
Also in this small example, removing --bundle from the build:server script is a workaround. However as I said, that is not an option in the larger app I want to use this in.

Let me know if you need more info.

from blues-stack.

JDouven avatar JDouven commented on April 28, 2024

@brophdawg11 I tried this and I can confirm this fixes the issue! Thanks!

from blues-stack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.