Skip to content

Commit

Permalink
fix(transformer/react): react refresh panics when encounter use hook (
Browse files Browse the repository at this point in the history
#5768)

close: #5766

I even forgot that React has a `use` hook in the latest version
  • Loading branch information
Dunqing committed Sep 13, 2024
1 parent e8bf30a commit 3cc38df
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/react/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ fn is_componentish_name(name: &str) -> bool {
}

fn is_use_hook_name(name: &str) -> bool {
name.starts_with("use") && name.chars().nth(3).unwrap().is_ascii_uppercase()
name.starts_with("use") && name.as_bytes().get(3).map_or(true, u8::is_ascii_uppercase)
}

#[rustfmt::skip]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default function App() {
const baz = FancyHook.useThing();
React.useState();
useThePlatform();
use();
return <h1>{bar}{baz}</h1>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export default function App() {
const baz = FancyHook.useThing();
React.useState();
useThePlatform();
use();
return _jsxs("h1", { children: [bar, baz] });
}
_s2(App, "useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}", true, function() {
_s2(App, "useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}\\nuse{}", true, function() {
return [FancyHook.useThing];
});
_c = App;
Expand Down

0 comments on commit 3cc38df

Please sign in to comment.