Skip to content
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

Throw when hook is invoked outside of render #2816

Merged
merged 2 commits into from
Nov 11, 2020

Conversation

marvinhagemeister
Copy link
Member

@marvinhagemeister marvinhagemeister commented Nov 5, 2020

Looks like we only threw when a hook was called from outside of a component for the very first component that was rendered. This was caused by currentComponent already being set at that point. See the previous code comment in the changeset.

This PR corrects that so that we keep track of valid hook positions and always throw if it's invalid.

Fixes #2574

@github-actions
Copy link

github-actions bot commented Nov 5, 2020

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -2% - +2% (-2.94ms - +2.53ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -4% - +4% (-1.19ms - +1.37ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -6% - +10% (-2.91ms - +5.10ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -3% - +1% (-0.08ms - +0.02ms)
    preact-local vs preact-master

window.usedJSHeapSize

  • 02_replace1k: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master

Results

02_replace1k
  • Browser: chrome-headless 86.0.4240.183
  • Sample size: 50
  • Built by: CI #457
  • Commit: d904941

duration

VersionAvg timevs preact-mastervs preact-local
preact-master158.34ms - 162.29ms-unsure 🔍
-2% - +2%
-2.53ms - +2.94ms
preact-local158.23ms - 162.00msunsure 🔍
-2% - +2%
-2.94ms - +2.53ms
-

window.usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master3.56ms - 3.57ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
preact-local3.57ms - 3.57msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-
03_update10th1k_x16
  • Browser: chrome-headless 86.0.4240.183
  • Sample size: 50
  • Built by: CI #457
  • Commit: d904941

duration

VersionAvg timevs preact-mastervs preact-local
preact-master30.53ms - 32.18ms-unsure 🔍
-4% - +4%
-1.37ms - +1.19ms
preact-local30.47ms - 32.42msunsure 🔍
-4% - +4%
-1.19ms - +1.37ms
-

window.usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master3.51ms - 3.52ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
preact-local3.51ms - 3.52msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-
many_updates
  • Browser: chrome-headless 86.0.4240.183
  • Sample size: 70
  • Built by: CI #457
  • Commit: d904941

duration

VersionAvg timevs preact-mastervs preact-local
preact-master48.69ms - 54.38ms-unsure 🔍
-10% - +5%
-5.10ms - +2.91ms
preact-local49.81ms - 55.45msunsure 🔍
-6% - +10%
-2.91ms - +5.10ms
-

window.usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master4.85ms - 4.85ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local4.85ms - 4.85msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
text_update
  • Browser: chrome-headless 86.0.4240.183
  • Sample size: 50
  • Built by: CI #457
  • Commit: d904941

duration

VersionAvg timevs preact-mastervs preact-local
preact-master3.01ms - 3.09ms-unsure 🔍
-1% - +3%
-0.02ms - +0.08ms
preact-local2.99ms - 3.05msunsure 🔍
-3% - +1%
-0.08ms - +0.02ms
-

window.usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master0.82ms - 0.82ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local0.82ms - 0.82msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-

tachometer-reporter-action v2 for CI

@coveralls
Copy link

coveralls commented Nov 5, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 3e93caa on invalid-hook-throw into 083935f on master.

@github-actions
Copy link

github-actions bot commented Nov 5, 2020

Size Change: +74 B (0%)

Total Size: 41.7 kB

Filename Size Change
hooks/dist/hooks.js 1.13 kB +25 B (2%)
hooks/dist/hooks.module.js 1.15 kB +26 B (2%)
hooks/dist/hooks.umd.js 1.2 kB +23 B (1%)
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.18 kB 0 B
compat/dist/compat.module.js 3.19 kB 0 B
compat/dist/compat.umd.js 3.24 kB 0 B
debug/dist/debug.js 3.12 kB 0 B
debug/dist/debug.module.js 3.11 kB 0 B
debug/dist/debug.umd.js 3.21 kB 0 B
devtools/dist/devtools.js 184 B 0 B
devtools/dist/devtools.module.js 195 B 0 B
devtools/dist/devtools.umd.js 260 B 0 B
dist/preact.js 4.02 kB 0 B
dist/preact.min.js 4.05 kB 0 B
dist/preact.module.js 4.04 kB 0 B
dist/preact.umd.js 4.08 kB 0 B
jsx-runtime/dist/jsxRuntime.js 296 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 305 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 373 B 0 B
test-utils/dist/testUtils.js 437 B 0 B
test-utils/dist/testUtils.module.js 439 B 0 B
test-utils/dist/testUtils.umd.js 515 B 0 B

compressed-size-action

Copy link
Member

@cristianbote cristianbote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@marvinhagemeister marvinhagemeister merged commit b8b42b3 into master Nov 11, 2020
@marvinhagemeister marvinhagemeister deleted the invalid-hook-throw branch November 11, 2020 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazy loading styled-components component triggers warning message incorrectly
4 participants