GithubHelp home page GithubHelp logo

Comments (9)

hoxyq avatar hoxyq commented on April 28, 2024 1

@jamesbvaughan, thanks for reporting this! Will take a look at it in a few days and reply back.

from react.

jamesbvaughan avatar jamesbvaughan commented on April 28, 2024 1

@hoxyq I can try to put together a PR this week.

from react.

jamesbvaughan avatar jamesbvaughan commented on April 28, 2024 1

I've put put a PR: #28399

from react.

hoxyq avatar hoxyq commented on April 28, 2024 1

@hoxyq Could you advise when the DevTools Firefox Extension will be updated? This issue affects me and it's good to see that it's been fixed but my browser is stuck on v5.0.0 of the extension from December.

I've uploaded v5.0.2 to Firefox store a week ago, its still pending review process.

from react.

jamesbvaughan avatar jamesbvaughan commented on April 28, 2024

I've made a bit more progress investigating this.

I believe the cause might be the two calls to nextHook in useSyncExternalStore:

function useSyncExternalStore<T>(
subscribe: (() => void) => () => void,
getSnapshot: () => T,
getServerSnapshot?: () => T,
): T {
// useSyncExternalStore() composes multiple hooks internally.
// Advance the current hook index the same number of times
// so that subsequent hooks have the right memoized state.
nextHook(); // SyncExternalStore
nextHook(); // Effect

To try to verify that, I found that just one other hook in that file, useTransition, also makes two calls to nextHook:

function useTransition(): [
boolean,
(callback: () => void, options?: StartTransitionOptions) => void,
] {
// useTransition() composes multiple hooks internally.
// Advance the current hook index the same number of times
// so that subsequent hooks have the right memoized state.
nextHook(); // State
nextHook(); // Callback

I modified my test case to use useTransition rather than useSyncExternalStore and confirmed that it also causes hook parsing to fail.

from react.

gm-al avatar gm-al commented on April 28, 2024

hey @hoxyq did you work on this?

from react.

Nathan-Roberts123 avatar Nathan-Roberts123 commented on April 28, 2024

function getPrimitiveStackCache(): Map<string, Array<any>> {
// This initializes a cache of all primitive hooks so that the top
// most stack frames added by calling the primitive hook can be removed.
if (primitiveStackCache === null) {
const cache = new Map<string, Array<any>>();
let readHookLog;
try {
// Use all hooks here to add them to the hook log.
Dispatcher.useContext(({_currentValue: null}: any));
Dispatcher.useState(null);
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
Dispatcher.useRef(null);
if (typeof Dispatcher.useCacheRefresh === 'function') {
// This type check is for Flow only.
Dispatcher.useCacheRefresh();
}
Dispatcher.useLayoutEffect(() => {});
Dispatcher.useInsertionEffect(() => {});
Dispatcher.useEffect(() => {});
Dispatcher.useImperativeHandle(undefined, () => null);
Dispatcher.useDebugValue(null);
Dispatcher.useCallback(() => {});
Dispatcher.useMemo(() => null);
if (typeof Dispatcher.useMemoCache === 'function') {
// This type check is for Flow only.
Dispatcher.useMemoCache(0);
}

When i was trying to debug this problem i notice that here they didn't call the useSyncExternalStore and useTransition from Dispatcher so I add the line Dispatcher.useSyncExternalStore(() => {}, () => {}, () => {}) above the line Dispatcher.useMemo(() => null) in above source code, and it worked fine. I don't know if this was intentionally or it a mistake.

from react.

hoxyq avatar hoxyq commented on April 28, 2024

function getPrimitiveStackCache(): Map<string, Array<any>> {
// This initializes a cache of all primitive hooks so that the top
// most stack frames added by calling the primitive hook can be removed.
if (primitiveStackCache === null) {
const cache = new Map<string, Array<any>>();
let readHookLog;
try {
// Use all hooks here to add them to the hook log.
Dispatcher.useContext(({_currentValue: null}: any));
Dispatcher.useState(null);
Dispatcher.useReducer((s: mixed, a: mixed) => s, null);
Dispatcher.useRef(null);
if (typeof Dispatcher.useCacheRefresh === 'function') {
// This type check is for Flow only.
Dispatcher.useCacheRefresh();
}
Dispatcher.useLayoutEffect(() => {});
Dispatcher.useInsertionEffect(() => {});
Dispatcher.useEffect(() => {});
Dispatcher.useImperativeHandle(undefined, () => null);
Dispatcher.useDebugValue(null);
Dispatcher.useCallback(() => {});
Dispatcher.useMemo(() => null);
if (typeof Dispatcher.useMemoCache === 'function') {
// This type check is for Flow only.
Dispatcher.useMemoCache(0);
}

When i was trying to debug this problem i notice that here they didn't call the useSyncExternalStore and useTransition from Dispatcher so I add the line Dispatcher.useSyncExternalStore(() => {}, () => {}, () => {}) above the line Dispatcher.useMemo(() => null) in above source code, and it worked fine. I don't know if this was intentionally or it a mistake.

Sorry for a late reply. Yes, this is required for generating stack frames of primitives, so this could be the root cause of why RDT can't find useSyncExternalStore hook.

@jamesbvaughan Thanks for providing the repro! Is someone interested in testing this solution against the repro and opening a PR?

from react.

kenlyon avatar kenlyon commented on April 28, 2024

@hoxyq Could you advise when the DevTools Firefox Extension will be updated? This issue affects me and it's good to see that it's been fixed but my browser is stuck on v5.0.0 of the extension from December.

from react.

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.