1. 19 8月, 2020 2 次提交
    • J
      Make `loadPage` track success of script loading (#16334) · 0a72d14d
      Joe Haddad 提交于
      Prior to this PR, `loadPage` would call `loadScript` which would then report if the script failed to load.
      
      This was problematic because `loadScript` notified a failure to load via `pageRegisterEvents`, which would not set the `pageCache` value for future requests.
      This means a one-off promise rejection would happen, [in lieu of being] typically consumed within the client-side router, causing a server-side reload.
      
      However, when `loadPage` was used independently (i.e. to preload pages), this promise rejection would be ignored as a preload failure.
      When the real routing request comes in, the `loadPage` function skips its attempt to load the `<script>` because it was already in the DOM, and the router would stop functioning.
      
      ---
      
      To fix this behavior, I've removed erroneous emits on `pageRegisterEvents` to only happen during the page registration lifecycle (its intended use).
      
      The new behavior is that `loadScript` returns a `Promise` that `loadPage` can track, and if any of the page(s) scripts fail to load, we mark the entire page as errored in `pageCache`. This ensures future requests to `loadPage` will always immediately reject with a `PAGE_LOAD_ERROR`, which causes the server-side redirect at the appropriate point.
      
      ---
      
      Fixes #16333
      0a72d14d
    • J
      Add `<link>` attributes in proper order (#16319) · ec07bf12
      Joe Haddad 提交于
      1. `as` should be set before `rel` in case of `preload` or `prefetch`
      2. `href` should be after `onload` and `onerror`
      ec07bf12
  2. 18 8月, 2020 2 次提交
  3. 13 8月, 2020 4 次提交
  4. 11 8月, 2020 1 次提交
  5. 07 8月, 2020 1 次提交
  6. 30 7月, 2020 1 次提交
  7. 28 7月, 2020 1 次提交
  8. 17 7月, 2020 1 次提交
  9. 15 7月, 2020 1 次提交
  10. 14 7月, 2020 1 次提交
    • J
      Replace node.js url module with WHATWG URL (#14827) · 3369d67b
      Jan Potoms 提交于
      Replace `url.parse` and `url.resolve` logic with whatwg `URL`, Bring in a customized `format` function to handle the node url objects that can be passed to router methods. This eliminates the need for `url` (and thus `native-url`) in core. Looks like it shaves off about 2.5Kb, according to the `size-limits` integration tests.
      3369d67b
  11. 13 7月, 2020 1 次提交
  12. 29 6月, 2020 1 次提交
  13. 23 6月, 2020 1 次提交
  14. 22 6月, 2020 1 次提交
  15. 21 6月, 2020 1 次提交
  16. 09 6月, 2020 1 次提交
  17. 08 6月, 2020 1 次提交
    • J
      Update handling for basePath to only automatically add (#13817) · 8dd3d2a8
      JJ Kasper 提交于
      As discussed, this streamlines the handling for `basePath` to not automatically strip and add the `basePath` when provided to `next/link` or `router.push/replace` and only automatically adds the `basePath` and when it is manually provided it will cause a 404 which ensures `href` still matches to the pages directory 1-to-1.
      
      This also adds additional test cases that we discussed to ensure this behavior is working as intended
      
      ---
      
      Fixes #13902
      8dd3d2a8
  18. 07 6月, 2020 1 次提交
  19. 05 6月, 2020 1 次提交
    • J
      Fix pages/index.js and pages/index/index.js behavior (#13699) · 1b36f0c0
      Jan Potoms 提交于
      Disambiguate between pages/index.js and pages/index/index.js so that they resolve differently.
      It all started with a bug in pagesmanifest that propagated throughout the codebase. After fixing pagesmanifest I was able to remove a few hacks here and there and more logic is shared now. especially the logic that resolves an entrypoint back into a route path. To sum up what happened:
      
      - `getRouteFromEntrypoint` is the inverse operation of `getPageFile` that's under `pages/_document.tsx`
      - `denormalizePagePath` is the inverse operation of `normalizePagePath`.
      
      Everything is refactored in terms of these operations, that makes their behavior uniform and easier to update/patch in a central place. Before there were subtle differences between those that made `index/index.js` hard to handle.
      
      Some potential follow up on this PR:
      - [`hot-reloader`](https://github.com/vercel/next.js/pull/13699/files#diff-6161346d2c5f4b7abc87059d8768c44bR207) still has one place that does very similar behavior to `getRouteFromEntrypoint`. It can probably be rewritten in terms of `getRouteFromEntrypoint`.
      - There are a few places where `denormalizePagePath(normalizePagePath(...))` is happening. This is a sign that `normalizePagePath` is doing some validation that is independent of its rewriting logic. That should probably be factored out in its own function. after that I should probably investigate whether `normalizePagePath` is even still needed at all.
      - a lot of code is doing `.replace(/\\/g, '')`. If wanted, that could be replaced with `normalizePathSep`.
      - It looks to me like some logic that's spread across the project can be centralized in 4 functions 
        - `getRouteFromEntrypoint` (part of this PR)
        - its inverse `getEntrypointFromRoute` (already exists in `_document.tsx` as `getPageFile`)
        - `getRouteFromPageFile` 
        - its inverse `getPageFileFromRoute` (already exists as `findPageFile ` in `server/lib/find-page-file.ts`)
      
        It could be beneficial to structure the code to keep these fuctionalities close together and name them similarly.
       - revise `index.amp` handling in pagesmanifest. I left it alone in this PR to keep it scoped, but it may be broken wrt nested index files as well. It might even make sense to reshape the pagesmanifest altogether to handle html/json/amp/... better
      1b36f0c0
  20. 02 6月, 2020 2 次提交
  21. 28 5月, 2020 1 次提交
  22. 19 5月, 2020 1 次提交
  23. 26 4月, 2020 1 次提交
  24. 06 3月, 2020 1 次提交
  25. 03 3月, 2020 1 次提交
    • J
      Prefetch SSG Data (#10127) · 990eda2c
      Joe Haddad 提交于
      * Prefetch SSG Data
      
      * Update packages/next/client/page-loader.js
      Co-Authored-By: NJJ Kasper <jj@jjsweb.site>
      
      * Revert router.ts
      
      * Revert link.tsx
      
      * undo change
      
      * mimmic existing
      
      * simplify
      
      * Prefetch href and asPath
      
      * fix load
      
      * dedupe prefetchAs
      
      * Inject script tag on hover
      
      * comment prefetchAs
      
      * minify code
      
      * introduce lazy files
      
      * Add some breathing room
      
      * correct default type
      
      * Prefetch non-dynamic data
      
      * Prefetch dynamic route data
      
      * Fix size test
      
      * Humanize code
      
      * add tests
      
      * Disable code
      
      * Only generate modern version in modern mode
      
      * Extract function helper
      
      * add comments
      
      * Filter out dynamic route to simplify manifest size
      
      * add test
      Co-authored-by: NJJ Kasper <jj@jjsweb.site>
      990eda2c
  26. 08 1月, 2020 1 次提交
  27. 06 1月, 2020 1 次提交
  28. 05 1月, 2020 1 次提交
  29. 01 1月, 2020 1 次提交
  30. 25 12月, 2019 1 次提交
  31. 24 12月, 2019 1 次提交
    • J
      Optimize Prefetching (#9818) · 632e40f2
      Joe Haddad 提交于
      * Optimize Prefetching
      
      * fix css client nav test
      
      * fix preload viewport test
      
      * fix production test
      
      * patch tests more
      
      * Make page loader wait on prefetch
      
      * no unhandled rejection
      
      * Save some bytes
      632e40f2
  32. 21 12月, 2019 1 次提交
  33. 14 12月, 2019 1 次提交
  34. 11 12月, 2019 1 次提交
    • J
      [Experimental] CSS Module Support (#9686) · 734989d8
      Joe Haddad 提交于
      * CSS Module Support
      
      * Fix Server-Side Render of CSS Modules
      
      * Fix Jest Snapshots
      https://github.com/facebook/jest/pull/8492
      
      * Fix snapshots
      
      * Add test for CSS module edit without remounting
      
      * Add tests for dev and production style being applied
      
      * Add missing TODOs
      
      * Include/exclude should only be applied to issuer, not the CSS file itself
      
      * Add CSS modules + node_modules tests
      
      * Test that content is correct
      
      * Create Multi Module Suite
      
      * Add client-side navigation support for CSS
      
      * Add tests for client-side nav
      
      * Add some delays
      
      * Try another fix
      
      * Increase timeout to 3 minutes
      
      * Fix test
      
      * Give all unique directories
      734989d8