Skip to content

fix(transformer/react): should not collect use-hooks if it's a nested member expression#6143

Merged
graphite-app[bot] merged 1 commit into
mainfrom
09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook
Sep 28, 2024
Merged

fix(transformer/react): should not collect use-hooks if it's a nested member expression#6143
graphite-app[bot] merged 1 commit into
mainfrom
09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook

Conversation

@Dunqing

@Dunqing Dunqing commented Sep 28, 2024

Copy link
Copy Markdown
Member

close: #6139

I still remember this logic and I call get_first_object for it intentionally 🥲

@graphite-app

graphite-app Bot commented Sep 28, 2024

Copy link
Copy Markdown
Contributor

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Dunqing commented Sep 28, 2024

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Dunqing and the rest of your teammates on Graphite Graphite

@github-actions github-actions Bot added the A-transformer Area - Transformer / Transpiler label Sep 28, 2024
@codspeed-hq

codspeed-hq Bot commented Sep 28, 2024

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #6143 will not alter performance

Comparing 09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook (bfd1988) with main (ab187d1)

Summary

✅ 29 untouched benchmarks

@Dunqing Dunqing force-pushed the 09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook branch from fce967e to eca9327 Compare September 28, 2024 13:25
@Dunqing Dunqing changed the title fix(transformer/react): should not collect it if it is a nested member expression use hook fix(transformer/react): should not collect use-hooks if it's a nested member expression Sep 28, 2024
@Dunqing Dunqing force-pushed the 09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook branch from eca9327 to 8e1c778 Compare September 28, 2024 13:30
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 28, 2024
@graphite-app

graphite-app Bot commented Sep 28, 2024

Copy link
Copy Markdown
Contributor

Merge activity

  • Sep 28, 10:33 AM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 28, 10:34 AM EDT: Boshen added this pull request to the Graphite merge queue.
  • Sep 28, 10:45 AM EDT: Boshen merged this pull request with the Graphite merge queue.

… member expression (#6143)

close: #6139

I still remember this logic and I call `get_first_object` for it intentionally 🥲
@Boshen Boshen force-pushed the 09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook branch from 8e1c778 to bfd1988 Compare September 28, 2024 14:38
@graphite-app graphite-app Bot merged commit bfd1988 into main Sep 28, 2024
@graphite-app graphite-app Bot deleted the 09-28-fix_transformer_react_should_not_collect_it_if_it_is_a_nested_member_expression_use_hook branch September 28, 2024 14:45
Boshen added a commit that referenced this pull request Sep 29, 2024
## [0.30.5] - 2024-09-29

### Features

- 15552ac napi/transform: Display semantic error (#6160) (Boshen)
- f50fdcd napi/transform: Make react refresh option take a boolean
(#6146) (Boshen)

### Bug Fixes

- f27d59f napi/transform: Remove confusing `jsx` option (#6159) (Boshen)
- bfd1988 transformer/react: Should not collect use-hooks if it's a
nested member expression (#6143) (Dunqing)

### Refactor

- ab187d1 codegen: Restrict visibility of internal methods (#6145)
(DonIsaac)
- 375bebe transformer: Improve parsing React pragmas (#6138)
(overlookmotel)
- 0836f6b transformer: Move parsing pragmas into TS transform (#6137)
(overlookmotel)
- 30424fa transformer: TS transforms only store options they need
(#6135) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
graphite-app Bot pushed a commit that referenced this pull request Jun 12, 2026
…23190)

## Summary

Ports react/react#35318 to the React Refresh plugin: hook calls through a nested member expression such as `FancyHook.property.useNestedThing()` are now collected into the `$RefreshSig$` custom-hooks list, so components using them no longer lose state on every fast-refresh update. As in the Babel plugin, the binding is resolved through one extra static member level, and a force reset is emitted when the root object has no binding in scope. Deeper nesting (`A.B.C.useHook()`) remains uncollected, same as upstream; note that Babel additionally emits `forceReset = true` in that case while oxc does not — a pre-existing, intentional divergence from #6143 that this PR does not change.

closes #16571

## Example

Input:

```jsx
import FancyHook from 'fancy';

export default function App() {
  const foo = FancyHook.property.useNestedThing();
  return <h1>{foo}</h1>;
}
```

Signature before:

```js
_s(App, "useNestedThing{foo}");
```

Signature after:

```js
_s(App, "useNestedThing{foo}", false, function() {
  return [FancyHook.property.useNestedThing];
});
```

---

This PR was prepared with AI assistance; I reviewed, tested, and verified the changes.
camc314 pushed a commit that referenced this pull request Jul 3, 2026
…23190)

## Summary

Ports react/react#35318 to the React Refresh plugin: hook calls through a nested member expression such as `FancyHook.property.useNestedThing()` are now collected into the `$RefreshSig$` custom-hooks list, so components using them no longer lose state on every fast-refresh update. As in the Babel plugin, the binding is resolved through one extra static member level, and a force reset is emitted when the root object has no binding in scope. Deeper nesting (`A.B.C.useHook()`) remains uncollected, same as upstream; note that Babel additionally emits `forceReset = true` in that case while oxc does not — a pre-existing, intentional divergence from #6143 that this PR does not change.

closes #16571

## Example

Input:

```jsx
import FancyHook from 'fancy';

export default function App() {
  const foo = FancyHook.property.useNestedThing();
  return <h1>{foo}</h1>;
}
```

Signature before:

```js
_s(App, "useNestedThing{foo}");
```

Signature after:

```js
_s(App, "useNestedThing{foo}", false, function() {
  return [FancyHook.property.useNestedThing];
});
```

---

This PR was prepared with AI assistance; I reviewed, tested, and verified the changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformer: React Refresh different output compared to babel

2 participants