在 nextjs 14 中使用服务器操作时,chrome devtools 无法正常工作

问题描述 投票:0回答:1

我正在 devTools 中检查网络请求,该请求针对

server action
中的
nextjs
发出。在响应部分,它有时会随机显示正确的响应,有时会显示
Failed to load response data: No data found for resource with given identifier
。我知道 devTools 存在 issue,当您导航到某个不同的网站后,它会显示此错误消息,但即使我在同一个网站上,尤其是
server actions
中的
nextjs
也会发生这种情况。

我认为这是一个问题,尤其是 nextjs 中的服务器操作。有人可以详细说明服务器操作到底出了什么问题吗?

PS:所有控制台日志在每个请求中都按预期工作,并且我得到的响应在 firefox devTools 中完全正常工作

这是

app/test_1/page.tsx
代码

"use client"
import { sayHello } from '../actions/testing';

function test_1() {
  async function handleClick() {
    console.log('Button clicked');
    try {
        const response = await sayHello();
        console.log('Response from server action:', response); // Should log { message: 'Hello, world!' }
    } catch (error) {
        console.error('Error calling server action:', error);
    }
}

  return (
      <div>
          <button onClick={handleClick}>Say Hello</button>
      </div>
);
}

export default test_1

这是

sayHello
app/actions/testing.ts

函数的代码
'use server';

export async function sayHello() {
    console.log('Server action called');
    const response = { message: 'Hello, world!' };
    console.log('Server action response:', response);
    return response;
}
request google-chrome-devtools response nextjs14 server-action
1个回答
0
投票

我也在问同样的问题。 https://www.reddit.com/r/nextjs/comments/1ho4iji/server_actions_fetch_failed_loading_post/

你有没有弄清楚这一点?是否得出结论可以安全地忽略?

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.