-
Notifications
You must be signed in to change notification settings - Fork 236
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
New Defer API does not work with blues-stack #151
Comments
switching from json to defer is not enough, you have to wrap the deferred data in See our guide on streaming: https://remix.run/docs/en/v1/guides/streaming#the-solution |
@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 |
If you want, feel free to remove |
🤦🏼♂️ sorry @justinwaite, reopened. |
Any new info regarding this? I'm running into this as well but removing |
@justinwaite @JDouven Does it work with the default Remix template? |
@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:
"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 Let me know if you need more info. |
This looks to be due to a failing // 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:
|
@brophdawg11 I tried this and I can confirm this fixes the issue! Thanks! |
The fix for this is out in |
Have you experienced this bug with the latest version of the template?
Yes
Steps to Reproduce
Setup the project
Create account and sign in
Update loader in notes.tsx to return
defer
instead ofjson
Expected Behavior
I would expect that just changing to
defer
while still resolving the promise in the loader would still work without any other changes, since the data is being awaited in the loader.Actual Behavior
The page errors with
TypeError: Cannot read properties of undefined (reading 'length')
When looking at the value of
data
fromconst data = useLoaderData<typeof loader>();
, it looks like this:This shape seems wrong to me. You should have to access the real data via
data.data
, right?The text was updated successfully, but these errors were encountered: